Changeset 9601 for src


Ignore:
Timestamp:
Aug 28, 2011, 8:53:06 PM (13 years ago)
Author:
rick
Message:

Initial import netstumbler file reader..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/management/commands/netstumbler.py

    r9600 r9601  
    1010from struct import *
    1111
    12 print ""
    13 fh = open('meting2.ns1','rb')
     12def parse_netstumbler(filename):
     13  fh = open(filename,'rb')
     14 
     15  def get_int32(size=1):
     16    return unpack('<' + 'i'*size,fh.read(4*size))
     17 
     18  def get_uint32(size=1):
     19    return unpack('<' + 'I'*size,fh.read(4*size))
     20 
     21  def get_uint64(size=1):
     22    return unpack('<' + 'Q'*size,fh.read(8*size))
     23 
     24  def get_uint8(size=1):
     25    return unpack('<' + 'B'*size,fh.read(1*size))
     26 
     27  def get_filetime():
     28    _FILETIME_null_date = datetime.datetime(1601, 1, 1, 0, 0, 0)
     29    ns = unpack('<Q',fh.read(8))[0] * 10
     30    sec = ns / 10**8
     31    d = datetime.timedelta(seconds=sec)
     32    return _FILETIME_null_date + d
     33 
     34  def get_char(size):
     35    return fh.read(size)
     36 
     37  def get_double(size=1):
     38    return unpack('<' + 'd'*size,fh.read(8*size))
     39 
     40  data = {}
     41 
     42  data["dwSignature"] = get_char(4)
     43  data["dwFileVerunpack"] = get_uint32()
     44  ApCount = get_uint32()[0]
     45  data["ApCount"] = ApCount
     46 
     47  data["aps"] = []
     48  for a in range(0,ApCount):
     49    ap = {}
     50    SSIDLength = get_uint8()[0]
     51    ap["SSIDLength"] = SSIDLength
     52    ap["SSID"] = get_char(SSIDLength)
     53    ap["BSSID"] = map(hex,unpack('BBBBBB',fh.read(6)))
     54    ap["MaxSignal"] = get_int32()
     55    ap["MinNoise"] = get_int32()
     56    ap["MaxSNR"] = get_int32()
     57    ap["Flags"] =  get_uint32()
     58    ap["BeaconInterval"] = get_uint32()
     59    ap["FirstSeen"] = get_filetime()
     60    ap["LastSeen"] = get_filetime()
     61    ap["BestLat"] = get_double()
     62    ap["BestLong"] = get_double()
     63    DataCount = get_uint32()[0]
     64    ap["DataCount"] = DataCount
     65    ap["measurement"] = []
     66    for c in range(0,DataCount):
     67      ms = {}
     68      ms["Time"] = get_filetime()
     69      ms["Signal"] = get_int32()
     70      ms["Noice"] = get_int32()
     71      LocationSource = get_int32()[0]
     72      ms["Location Source"] = LocationSource
     73      if LocationSource == 1:
     74        ms["Latitude"] = get_double()
     75        ms["Longitude"] = get_double()
     76        ms["Altitude"] = get_double()
     77        ms["NumStats"] = get_uint32()
     78        ms["Speed"] = get_double()
     79        ms["Track"] = get_double()
     80        ms["MagVariation"] = get_double()
     81        ms["Hdop"] = get_double()
     82      ap["measurement"].append(ms)
     83    NameLength = get_uint8()[0]
     84    ap["NameLength"] = NameLength
     85    ap["Name"] = get_char(NameLength)
     86    ap["Channels"] = get_uint64()
     87    ap["LastChannel"] = get_uint32()
     88    ap["IPAddress"] = get_uint32()
     89    ap["MinSignal"] = get_int32()
     90    ap["MaxSignal"] = get_int32()
     91    ap["DataRate"] = get_uint32()
     92    ap["IPSubnet"] = get_uint32()
     93    ap["IPMask"] = get_uint32()
     94    ap["ApFlags"] = get_uint32()
     95    IELength = get_uint32()[0]
     96    ap["IELength"] = IELength
     97    ap["InformationElements"] = get_uint8(IELength)
     98    data["aps"].append(ap)
     99  return data
    14100
    15 def get_int32(size=1):
    16   return unpack('<' + 'i'*size,fh.read(4*size))
    17 
    18 def get_uint32(size=1):
    19   return unpack('<' + 'I'*size,fh.read(4*size))
    20 
    21 def get_uint64(size=1):
    22   return unpack('<' + 'Q'*size,fh.read(8*size))
    23 
    24 def get_uint8(size=1):
    25   return unpack('<' + 'B'*size,fh.read(1*size))
    26 
    27 def get_filetime():
    28   _FILETIME_null_date = datetime.datetime(1601, 1, 1, 0, 0, 0)
    29   ns = unpack('<Q',fh.read(8))[0] * 10
    30   sec = ns / 10**8
    31   d = datetime.timedelta(seconds=sec)
    32   return _FILETIME_null_date + d
    33 
    34 def get_char(size):
    35   return fh.read(size)
    36 
    37 def get_double(size=1):
    38   return unpack('<' + 'd'*size,fh.read(8*size))
    39 
    40 
    41 print "dwSignature:", get_char(4)
    42 print "dwFileVerunpack:", get_uint32()
    43 ApCount = get_uint32()[0]
    44 print "ApCount:", ApCount
    45 
    46 for a in range(0,ApCount):
    47   SSIDLength = get_uint8()[0]
    48   print "SSIDLength:", SSIDLength
    49   print "SSID:", get_char(SSIDLength)
    50   print "BSSID:", map(hex,unpack('BBBBBB',fh.read(6)))
    51   print "MaxSignal:", get_int32()
    52   print "MinNoise:", get_int32()
    53   print "MaxSNR:", get_int32()
    54   print "Flags:", get_uint32()
    55   print "BeaconInterval:", get_uint32()
    56   print "FirstSeen:", get_filetime()
    57   print "LastSeen:", get_filetime()
    58   print "BestLat:", get_double()
    59   print "BestLong:", get_double()
    60   DataCount = get_uint32()[0]
    61   print "DataCount:", DataCount
    62   for c in range(0,DataCount):
    63     print "Time:", get_filetime()
    64     print "Signal:", get_int32()
    65     print "Noice:", get_int32()
    66     LocationSource = get_int32()[0]
    67     print "Location Source:", LocationSource
    68     if LocationSource == 1:
    69       print "Latitude:", get_double()
    70       print "Longitude:", get_double()
    71       print "Altitude:", get_double()
    72       print "NumStats:", get_uint32()
    73       print "Speed:", get_double()
    74       print "Track:", get_double()
    75       print "MagVariation:", get_double()
    76       print "Hdop:", get_double()
    77   NameLength = get_uint8()[0]
    78   print "NameLength:", NameLength
    79   print "Name:", get_char(NameLength)
    80   print "Channels:", get_uint64()
    81   print "LastChannel:", get_uint32()
    82   print "IPAddress:", get_uint32()
    83   print "MinSignal:", get_int32()
    84   print "MaxSignal:", get_int32()
    85   print "DataRate:", get_uint32()
    86   print "IPSubnet:", get_uint32()
    87   print "IPMask:", get_uint32()
    88   print "ApFlags:", get_uint32()
    89   IELength = get_uint32()[0]
    90   print "IELength:", IELength
    91   print "InformationElements:", get_uint8(IELength)
     101print parse_netstumbler(sys.argv[1])
Note: See TracChangeset for help on using the changeset viewer.