Parsing ns1 files in PHP - Opensource

Take a script, leave a script - Like the penny tray only different

Parsing ns1 files in PHP - Opensource

Postby janolap1 » Thu Jan 06, 2005 2:43 am

Hi,

Obviously, some people want to display the ns1 files from netstumbler on the internet... (enhancing my webstumbler script (Link on netstumbler forums) )
So I'm trying to create a script to do this.
I'm working on it but still have some problems.

This is the script :
[PHP]
<?php
$jump=0;

function dwSignature($s,$offset)
//4 dwSignature char[4] File Signature ('NetS')
{
global $jump;
$jump=$jump+4;
return substr($s,$offset,4);
}

function dwFileVer($s,$offset)
//4 dwFileVer uint32 File Format Version
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function ApCount($s,$offset)
//4 ApCount uint32 Number of APINFO entries that follow
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function SSIDLength($s,$offset)
//1 SSIDLength uint8 Length of SSID
{
global $jump;
$jump=$jump+1;
return hexdec(bin2hex($s[$offset]));
}

function SSID($s,$length,$offset)
//SSIDLength SSID char[] SSID (SSIDLength characters, no terminating null)
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}

function BSSID($s, $offset)
//6 BSSID uint8[6] BSSID
{
global $jump;
$jump=$jump+6;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]));
}

function MaxSignal($s, $offset)
//4 MaxSignal int32 Maximum reported signal level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function MinNoise($s,$offset)
// 4 MinNoise int32 Minimum reported noise level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function MaxSNR($s,$offset)
// 4 MaxSNR int32 Maximum reported signal-to-noise ratio, dB
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function Flags($s,$offset)
// 4 Flags uint32 802.11 capability flags
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function BeaconInterval ($s,$offset)
// 4 BeaconInterval uint32 Beacon Interval, Kµs
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function FirstSeen ($s,$offset)
// 8 FirstSeen FILETIME Time first seen
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&hexdec(bin2hex($s[7+$offset]));
}

function LastSeen ($s,$offset)
// 8 LastSeen FILETIME Time last seen
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}

function BestLat ($s,$offset)
// 8 BestLat double Estimated Latitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}

function BestLong ($s,$offset)
// 8 BestLong double Estimated Longitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}

function DataCount ($s,$offset)
// 4 DataCount uint32 Number of APDATA entries that follow
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function ApData ($s,$length, $offset)
// Variable ApData APDATA[] DataCount APDATA entries
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}

function NameLength ($s, $offset)
// 1 NameLength uint8 Length of Name
{
global $jump;
$jump=$jump+1;
return hexdec(bin2hex($s[0+$offset]));
}

function Name ($s, $length, $offset)
// NameLength Name char[] Name (NameLength characters, no terminating null)
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}

function Channels ($s, $offset)
// 8 Channels uint64 Bit field indicating channel activity
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function LastChannel ($s, $offset)
// 4 LastChannel uint32 Last reported channel
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function IPAddress ($s, $offset)
// 4 IPAddress uint32 IP Address
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}

function MinSignal ($s, $offset)
// 4 MinSignal int32 Minimum reported signal level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function MaxNoise ($s, $offset)
// 4 MaxNoise int32 Maximum reported noise level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function DataRate ($s, $offset)
// 4 DataRate uint32 Highest reported data rate, units of 100 kbps
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function IPSubnet ($s, $offset)
// 4 IPSubnet uint32 IP Subnet address
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}

function IPMask ($s, $offset)
// 4 IPMask uint32 IP Subnet mask
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}

function ApFlags ($s, $offset)
// 4 ApFlags uint32 Miscellaneous Flags
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function IELength ($s, $offset)
// 4 IELength uint32 Number of bytes that follow (0 except when using NDIS 5.1 with a WPA capable driver)
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function InformationElements ($s,$length, $offset)
// IELength InformationElements uint8[] 802.11 Information Elements
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}

function APInfo($s, $offset, $number)
//Variable ApInfo APINFO[] ApCount APINFO entries
{
global $jump;
for ($i=1; $i<=$number; $i++)
{
global $jump;
echo $jump;
$SSIDLength = SSIDLength($s,$jump);
echo "SSIDLength = ".$SSIDLength;
echo "
";
echo "SSID = ".SSID($s, $SSIDLength, $jump);
echo "
";
echo "BSSID = ".BSSID($s,$jump);
echo "
";
echo "MaxSignal = ".MaxSignal($s,$jump);
echo "
";
echo "MinNoise = ".MinNoise($s,$jump);
echo "
";
echo "MaxSNR = ".MaxSNR($s,$jump);
echo "
";
echo "Flags = ".Flags($s,$jump);
echo "
";
echo "BeaconInterval = ".BeaconInterval($s,$jump);
echo "
";
echo "FirstSeen = ".FirstSeen($s,$jump);
echo "
";
echo "LastSeen = ".LastSeen($s,$jump);
echo "
";
echo "BestLat = ".BestLat($s,$jump);
echo "
";
echo "BestLong = ".BestLong($s,$jump);
echo "
";
$DataCount = DataCount($s,$jump);
echo "DataCount = ".$DataCount;
echo "
";
echo "ApData = ".ApData($s, $DataCount, $jump);
echo "
";
$NameLength = NameLength($s,$jump);
echo "NameLength = ".$NameLength;
echo "
";
echo "Name = ".Name($s, $NameLength, $jump);
echo "
";
echo "Channels = ".Channels($s,$jump);
echo "
";
echo "LastChannel = ".LastChannel($s,$jump);
echo "
";
echo "IPAddress = ".IPAddress($s,$jump);
echo "
";
echo "MinSignal = ".MinSignal($s,$jump);
echo "
";
echo "MaxNoise = ".MaxNoise($s,$jump);
echo "
";
echo "DataRate = ".DataRate($s,$jump);
echo "
";
echo "IPSubnet = ".IPSubnet($s,$jump);
echo "
";
echo "IPMask = ".IPMask($s,$jump);
echo "
";
echo "ApFlags = ".ApFlags($s,$jump);
echo "
";
$IELength = IELength($s,$jump);
echo "IELength = ".$IELength;
echo "
";
echo "InformationElements = ".InformationElements($s, $IELength, $jump);
echo "<hr>";
}
}

// Read the file and put the content in a string
$filename = "netstumbler.ns1";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);

echo "Signature of the file = ".dwSignature($contents,$jump);
echo "
";
echo "File version = ".dwFileVer($contents,$jump);
echo "
";
$APCount = ApCount($contents,$jump);
echo " Number of AP = ".$APCount;
echo "<hr>";
echo APInfo($contents,$jump,$APCount);

php?>
[/PHP]

Just put the script on your webserver, a ns1 file called netstumbler.ns1 and call the script.

The problems are :
- Some info are not correctly converted
- I only display 1 AP (because of IELength)

I you want to enhance this script... contact me to help me.

It's GPL so do what you want with it...

Cordially

Jean CARTIER
janolap1
Mini Stumbler
 
Posts: 9
Joined: Sat Nov 27, 2004 3:34 pm

Postby The Others » Thu Jan 06, 2005 6:16 am

janolap1 wrote:I only display 1 AP (because of IELength)


That was the problem I had. Never mind, the dtauls shown about that one access point were nice ;)
all good ends all

?u=273
User avatar
The Others
 
Posts: 2910
Joined: Mon Apr 22, 2002 7:27 am
Location: Dos Palabras, Mandoras

Got it !

Postby janolap1 » Thu Jan 13, 2005 8:11 am

Hi,

I have found the problem in my script.
The GPS data and the AP data were missing.
I'll correct this asap and post the result on this forum.

Jean CARTIER
janolap1
Mini Stumbler
 
Posts: 9
Joined: Sat Nov 27, 2004 3:34 pm

It finally works

Postby janolap1 » Fri Jan 14, 2005 2:23 am

Hi,

I finally make my script work.
you can test it if you want and tell me if it's cool.
I would like to enhance it to convert data format, and to make it more readable.

This is the script...
[PHP]<?php

//
// NS1 to HTML in PHP
// Created by Jean CARTIER
// v 1.0 - 14-jan-2005
// For NetStumbler 0.4
// Under GPL Licence (See http://www.gnu.org/copyleft/gpl.html )
// ToDo : Convert results to be readable (LongInt to Date and time, Speed, ...)

//Constants to be displayed :
$header = "HEADER";
$apinfo = "AP Info";
$apnumber = "AP number";
$extrainfos = "Extra infos";
$apdatanumber = "AP Data number";


$jump=0;

//
// ***************** HEAD **************************
//
function dwSignature($s,$offset)
//4 dwSignature char[4] File Signature ('NetS')
{
global $jump;
$jump=$jump+4;
return substr($s,$offset,4);
}

function dwFileVer($s,$offset)
//4 dwFileVer uint32 File Format Version
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function ApCount($s,$offset)
//4 ApCount uint32 Number of APINFO entries that follow
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}
//
// *********************************************
//

//
// ****************** GPS DATA ***************************
//
function Latitude($s, $offset)
//8 Latitude double Reported latitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function Longitude($s, $offset)
//8 Longitude double Reported longitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function Altitude($s, $offset)
//8 Altitude double Reported altitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function NumSats($s, $offset)
//4 NumSats uint32 Number of satellites in view of GPS receiver
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function Speed($s, $offset)
//8 Speed double Reported speed
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function Track($s, $offset)
//8 Track double Reported track
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function MagVariation($s, $offset)
//8 MagVariation double Reported magnetic variation
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function Hdop($s, $offset)
//8 Hdop double Reported HDOP
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}
//
// *********************************************
//


//
// ******************* APDATA **************************
//
function Time_($s, $offset)
//8 Time FILETIME Time that this data was collected
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function Signal($s, $offset)
//4 Signal int32 Reported Signal, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function Noise($s, $offset)
//4 Noise int32 Reported Noise, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function LocationSource($s, $offset)
//4 Location Source int32 Kind of location fix (None=0, GPS=1)
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function GPSData($s)
//0 or sizeof(GPSDATA) GpsData GPSDATA If LocationSource is None(0), this structure is not present.
{
global $jump;
echo "
Latitude :".Latitude($s,$jump);
echo "
Longitude :".Longitude($s,$jump);
echo "
Altitude :".Altitude($s,$jump);
echo "
NumSats :".NumSats($s,$jump);
echo "
Speed :".Speed($s,$jump);
echo "
Track :".Track($s,$jump);
echo "
MagVariation :".MagVariation($s,$jump);
echo "
Hdop :".Hdop($s,$jump);
}
//
// *********************************************
//



//
// ***************** APINFO **************************
//
function SSIDLength($s,$offset)
//1 SSIDLength uint8 Length of SSID
{
global $jump;
$jump=$jump+1;
return hexdec(bin2hex($s[$offset]));
}

function SSID($s,$length,$offset)
//SSIDLength SSID char[] SSID (SSIDLength characters, no terminating null)
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}

function BSSID($s, $offset)
//6 BSSID uint8[6] BSSID
{
global $jump;
$jump=$jump+6;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]));
}

function MaxSignal($s, $offset)
//4 MaxSignal int32 Maximum reported signal level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function MinNoise($s,$offset)
// 4 MinNoise int32 Minimum reported noise level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function MaxSNR($s,$offset)
// 4 MaxSNR int32 Maximum reported signal-to-noise ratio, dB
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function Flags($s,$offset)
// 4 Flags uint32 802.11 capability flags
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function BeaconInterval ($s,$offset)
// 4 BeaconInterval uint32 Beacon Interval, Kµs
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function FirstSeen ($s,$offset)
// 8 FirstSeen FILETIME Time first seen
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&hexdec(bin2hex($s[7+$offset]));
}

function LastSeen ($s,$offset)
// 8 LastSeen FILETIME Time last seen
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}

function BestLat ($s,$offset)
// 8 BestLat double Estimated Latitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}

function BestLong ($s,$offset)
// 8 BestLong double Estimated Longitude
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))&":"&hexdec(bin2hex($s[1+$offset]))&":"&hexdec(bin2hex($s[2+$offset]))&":"&hexdec(bin2hex($s[3+$offset]))&":"&hexdec(bin2hex($s[4+$offset]))&":"&hexdec(bin2hex($s[5+$offset]))&":"&hexdec(bin2hex($s[6+$offset]))&":"&hexdec(bin2hex($s[7+$offset]));
}

function DataCount ($s,$offset)
// 4 DataCount uint32 Number of APDATA entries that follow
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function ApData ($s,$count)
// Variable ApData APDATA[] DataCount APDATA entries
{
global $jump;
global $apdatanumber;
for ($i=1;$i<=$count;$i++)
{
echo "
<h3>$apdatanumber $i</h3>";
$time_ = Time_($s,$jump);
echo "Time :".$time_;
echo "
Signal :".Signal($s,$jump);
echo "
Noise :".Noise($s,$jump);
$locationsource = LocationSource($s,$jump);
echo "
Location Source : ".$locationsource;
if ($locationsource>0)
{echo GPSData($s);}
}
}

function NameLength ($s, $offset)
// 1 NameLength uint8 Length of Name
{
global $jump;
$jump=$jump+1;
return hexdec(bin2hex($s[0+$offset]));
}

function Name ($s, $length, $offset)
// NameLength Name char[] Name (NameLength characters, no terminating null)
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}

function Channels ($s, $offset)
// 8 Channels uint64 Bit field indicating channel activity
{
global $jump;
$jump=$jump+8;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]))+255*255*255*255*hexdec(bin2hex($s[4+$offset]))+255*255*255*255*255*hexdec(bin2hex($s[5+$offset]))+255*255*255*255*255*255*hexdec(bin2hex($s[6+$offset]))+255*255*255*255*255*255*255*hexdec(bin2hex($s[7+$offset]));
}

function LastChannel ($s, $offset)
// 4 LastChannel uint32 Last reported channel
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function IPAddress ($s, $offset)
// 4 IPAddress uint32 IP Address
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}

function MinSignal ($s, $offset)
// 4 MinSignal int32 Minimum reported signal level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function MaxNoise ($s, $offset)
// 4 MaxNoise int32 Maximum reported noise level, dBm
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function DataRate ($s, $offset)
// 4 DataRate uint32 Highest reported data rate, units of 100 kbps
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function IPSubnet ($s, $offset)
// 4 IPSubnet uint32 IP Subnet address
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}

function IPMask ($s, $offset)
// 4 IPMask uint32 IP Subnet mask
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset])).":".hexdec(bin2hex($s[1+$offset])).":".hexdec(bin2hex($s[2+$offset])).":".hexdec(bin2hex($s[3+$offset]));
}

function ApFlags ($s, $offset)
// 4 ApFlags uint32 Miscellaneous Flags
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function IELength ($s, $offset)
// 4 IELength uint32 Number of bytes that follow (0 except when using NDIS 5.1 with a WPA capable driver)
{
global $jump;
$jump=$jump+4;
return hexdec(bin2hex($s[0+$offset]))+255*hexdec(bin2hex($s[1+$offset]))+255*255*hexdec(bin2hex($s[2+$offset]))+255*255*255*hexdec(bin2hex($s[3+$offset]));
}

function InformationElements ($s,$length, $offset)
// IELength InformationElements uint8[] 802.11 Information Elements
{
global $jump;
$jump=$jump+$length;
return substr($s,$offset,$length);
}
//
// *******************************************
//

function APInfo($s, $number)
//Variable ApInfo APINFO[] ApCount APINFO entries
{
global $jump;
global $extrainfos;
for ($i=1; $i<=$number; $i++)
{
echo "<H2>apnumber $i</h2>";
$SSIDLength = SSIDLength($s,$jump);
echo "SSIDLength = ".$SSIDLength;
echo "
SSID = ".SSID($s, $SSIDLength, $jump);
echo "
BSSID = ".BSSID($s,$jump);
echo "
MaxSignal = ".MaxSignal($s,$jump);
echo "
MinNoise = ".MinNoise($s,$jump);
echo "
MaxSNR = ".MaxSNR($s,$jump);
echo "
Flags = ".Flags($s,$jump);
echo "
BeaconInterval = ".BeaconInterval($s,$jump);
echo "
FirstSeen = ".FirstSeen($s,$jump);
echo "
LastSeen = ".LastSeen($s,$jump);
echo "
BestLat = ".BestLat($s,$jump);
echo "
BestLong = ".BestLong($s,$jump);
$DataCount = DataCount($s,$jump);
echo "
DataCount = ".$DataCount;
ApData($s, $DataCount);
echo "<h3>$extrainfos</h3>";
$NameLength = NameLength($s,$jump);
echo "NameLength = ".$NameLength;
echo "
Name = ".Name($s, $NameLength, $jump);
echo "
Channels = ".Channels($s,$jump);
echo "
LastChannel = ".LastChannel($s,$jump);
echo "
IPAddress = ".IPAddress($s,$jump);
echo "
MinSignal = ".MinSignal($s,$jump);
echo "
MaxNoise = ".MaxNoise($s,$jump);
echo "
DataRate = ".DataRate($s,$jump);
echo "
IPSubnet = ".IPSubnet($s,$jump);
echo "
IPMask = ".IPMask($s,$jump);
echo "
ApFlags = ".ApFlags($s,$jump);
$IELength = IELength($s,$jump);
echo "
IELength = ".$IELength;
echo "
InformationElements = ".InformationElements($s, $IELength, $jump);
echo "
<hr>";
}
}

// Read the file and put the content in a string
$filename = "netstumbler.ns1";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
echo "<h1>$header</h1>";
echo "Signature of the file = ".dwSignature($contents,$jump);
echo "
File version = ".dwFileVer($contents,$jump);
$APCount = ApCount($contents,$jump);
echo "
Number of AP = ".$APCount;
echo "
<hr><h1>$apinfo</h1><hr>";
APInfo($contents,$APCount);
?>[/PHP]

Enjoy

Jean CARTIER
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

janolap1
Mini Stumbler
 
Posts: 9
Joined: Sat Nov 27, 2004 3:34 pm

strange result

Postby widyawan » Mon Feb 14, 2005 10:55 pm

janolap1 wrote:Hi,

I finally make my script work.
you can test it if you want and tell me if it's cool.
I would like to enhance it to convert data format, and to make it more readable.

This is the script...
[PHP]<?php


Hi ...

I have tried your script. It's work unless that I can not understand the number that represent signal/noise. My php output file looks like this

......
AP Data number 6
Time :1.24295290856E+017
Signal :4244897216
Noise :4244897181
Location Source : 0
.........

How can I read this in dBm (as it show in .ns1 file)?

Thanks
widyawan
Mini Stumbler
 
Posts: 5
Joined: Fri Feb 11, 2005 9:09 pm

Readable output

Postby janolap1 » Tue Feb 15, 2005 4:20 am

Hi,

Thanx for testing the script.

The problem is that I don't have enough time to transform output into DBm, or whatever. If you have the time, and a little programming skills, try to enhance it.

I'll try to make a better script later.

Cordially

Jean CARTIER
janolap1
Mini Stumbler
 
Posts: 9
Joined: Sat Nov 27, 2004 3:34 pm

Postby beakmyn » Tue Feb 15, 2005 5:22 am

The number is already in dBm you're just translating it wrong. It's a 4 byte signed integer.

The time looks the way it does because it's stored in the file as a FILETIME structure which is two longs that need to be 'transmorgified'.

I use the following function to handle 90% of the data types in the Ns1 file
I'm not the author of this function
Code: Select all
Function BytesToNumEx(ByteArray() As Byte, StartRec As Long, _
   EndRec As Long, UnSigned As Boolean) As Double
' ###################################################
' Author                : Imran Zaheer
' Contact               : imraanz@mail.com
' Date                  : January 2000
' Function BytesToNumEx : Convertes the specified byte array
'                         into the corresponding Integer or Long
'                         or any signed/unsigned
'                        ;(non-float) data type.
'
' * BYTES : LIKE NUMBERS(Integer/Long etc.) STORED IN A
' * BINARY FILE

' Parameters :
'  (All parameters are reuuired: No Optional)
'     ByteArray() : byte array containg a number in byte format
'  StartRec    : specify the starting array record within the
                 ' array
'     EndRec      : specify the end array record within the array
'     UnSigned    : when False process bytes for both -ve and
'                   +ve values.
'                   when true only process the bytes for +ve
'                   values.
'
' Note: If both "StartRec" and "EndRec" Parameters are zero,
'       then the complete array will be processed.
'
' Example Calls :
'      dim myArray(1 To 4) as byte
'      dim myVar1 as Integer
'      dim myVar2 as Long
'
'      myArray(1) = 255
'      myArray(2) = 127
'      myVar1 = BytesToNumEx(myArray(), 1, 2, False)
'  after execution of above statement myVar1 will be 32767
'
'      myArray(1) = 0
'      myArray(2) = 0
'      myArray(3) = 0
'      myArray(4) = 128
'      myVar2 = BytesToNumEx(myArray(), 1, 4, False)
'  after execution of above statement myVar2 will be -2147483648
'
'
'####################################################
On Error GoTo ErrorHandler
Dim i As Integer
Dim lng256 As Double
Dim lngReturn As Double
   
    lng256 = 1
    lngReturn = 0
   
    If EndRec < 1 Then
        EndRec = UBound(ByteArray)
    End If
   
    If StartRec > EndRec Or StartRec < 0 Then
        MsgBox _
         "Start record can not be greater then End record...!", _
          vbInformation
        BytesToNumEx = -1
        Exit Function
    End If
   
    lngReturn = lngReturn + (ByteArray(StartRec))
    For i = (StartRec + 1) To EndRec
        lng256 = lng256 * 256
        If i < EndRec Then
            lngReturn = lngReturn + (ByteArray(i) * lng256)
        Else
           ' if -ve

            If ByteArray(i) > 127 And UnSigned = False Then
             lngReturn = (lngReturn + ((ByteArray(i) - 256) _
                  * lng256))
            Else
                lngReturn = lngReturn + (ByteArray(i) * lng256)
            End If
        End If
    Next i
   
    BytesToNumEx = lngReturn
ErrorHandler:
End Function



The FILETIME is a bit harder as it needs to be converted from a UTC FILETIME to a LOCAL FILETIME then to a SYSTEMTIME then to a standard date and time.
beakmyn
 
Posts: 4858
Joined: Sun Aug 03, 2003 1:53 pm

Postby widyawan » Wed Feb 16, 2005 11:38 pm

beakmyn wrote:The number is already in dBm you're just translating it wrong. It's a 4 byte signed integer.

The time looks the way it does because it's stored in the file as a FILETIME structure which is two longs that need to be 'transmorgified'.



Hi thanks for the respond ...

4 bytes signed integer? So if we have 10 dbm (1010) it will show as 0101 0000 0000 0000 0000 0000 0000 0000 (1342177280 in dec)?
Your function is written in VB ? And its for conversting to ' normal' dbm?

Cheer
Widy
widyawan
Mini Stumbler
 
Posts: 5
Joined: Fri Feb 11, 2005 9:09 pm

Postby beakmyn » Thu Feb 17, 2005 5:01 am

It's written in vb. I read 4 bytes from the file into a byte array and pass it through the function and get a human readable number.

MaxSignal 4 bytes int32 Maximum signal level reported in dBm

After reading 4 bytes from the file
Bytes(0)=188
Bytes(1)=255
Bytes(2)=255
Bytes(3)=255

Pass byte array to function
ns1.APINFO(Index).MaxSignal = BytesToNumEx(bytes, 0, 0, False)

Result of Function
-68
beakmyn
 
Posts: 4858
Joined: Sun Aug 03, 2003 1:53 pm

Postby Evil.2000 » Wed Jul 27, 2005 9:50 am

OK.

There is a little line to get this worked in PHP.

$value holds the BINARY Data for the Noise and Signal Rate.
i.e. $value is œÿÿÿ which is hex 0x9cffffff or decimal 2634022911
But that is not the real value. The Real one is -100 dBm.
Because the bytes for this value in the file are reversed and we have to reverse it again.
Now it is 0xffffff9c or decimal 4294967196
Then invert all the bytes (0x000063) and convert it to decimal (99) and add 1 (100).
Give it the "-" sign and be happy ;)

We have -100. Thats the right value.

The Code:
[PHP]$dBm = "-".(hexdec(bin2hex(~(strrev($value))))+1);[/PHP]

EDIT:
But don't forget: This workes only for negative Values.
If you have a positive number such as MaxSNR you don't have to invert the bytes and don't add 1.
PHP-Code looks like this:
[PHP]$dBm = hexdec(bin2hex(strrev($value)));[/PHP]

HTH

Evil
Evil.2000
Mini Stumbler
 
Posts: 4
Joined: Wed Jul 27, 2005 9:32 am

Postby Evil.2000 » Thu Jul 28, 2005 2:39 pm

OK guys, i've a problem and hopefully someone can help me.

I've wirtten a NS1-Parser in PHP.
It works fine but i have trouble with 2 Variables.

If you export the data as SUM-File there are the fields with its values like this:
Code: Select all
[ SNR Sig Noise ]
[ 98 47 -51 ]

OK. how does Netstumbler calculate the Sig and Noise Values?
If i parse the NS1-File there isn't a field containong the values 47 and -51.
The fields [MaxSignal] => -102 and [MinNoise] => -200 are other values and the [MinSignal]and [MaxNoise] give values like 1235368 and 14549456.

So can anyone tell me how Netstumbler calculates the Sig and Noise in it's SUM-Files?

Thanx for Help.

Evil.2000
Evil.2000
Mini Stumbler
 
Posts: 4
Joined: Wed Jul 27, 2005 9:32 am

Postby Thorn » Thu Jul 28, 2005 2:43 pm

Search on "149"
Thorn
Stop the TSA now! Boycott the airlines.
Thorn
 
Posts: 10340
Joined: Sat Apr 13, 2002 3:00 am
Location: Villa Straylight

Postby Evil.2000 » Thu Jul 28, 2005 2:46 pm

Thorn wrote:Search on "149"

Sorry there isn't a field containing 149.

Can you explain to me how to get on 149?

EDIT:
OK. Please give me next time the hint to search for 149 on the forum not in my Values ;) :P
Evil.2000
Mini Stumbler
 
Posts: 4
Joined: Wed Jul 27, 2005 9:32 am

odd bug

Postby gabecrowe » Fri Apr 27, 2007 4:55 am

got a parsing problem there chaps:
[quote]InformationElements = ���ðè,—{Ç£ÿÿÿœÿÿÿ����@9ú-—{Ç€ÿÿ€ÿÿ����P°½.—{Ǫÿÿÿœÿÿÿ����
gabecrowe
Mini Stumbler
 
Posts: 1
Joined: Wed Apr 11, 2007 6:59 am

Postby MikeP928 » Fri Apr 27, 2007 6:50 am

gabecrowe wrote:got a parsing problem there chaps:


Has anyone made a working version of this?


Proceed immediately to the Welcome Desk and read ALL the threads there. Your duration on this forum will be greatly effected by how well you use the info there.

Or you can just Procreate Elsewhere for Zombie thread revival.

MikeP
Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote.
-- Benjamin Franklin, 1759
User avatar
MikeP928
 
Posts: 1122
Joined: Wed May 01, 2002 8:09 pm
Location: Florida Panhandle

Next

Return to Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron