Ignore:
Timestamp:
Aug 30, 2011, 2:13:01 PM (13 years ago)
Author:
rick
Message:

Cosmetic fixes.

File:
1 edited

Legend:

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

    r9602 r9618  
    55# Rick van der Zwet <info@rickvanderzwet.nl>
    66#
    7 import sys
    87import datetime
     8from struct import unpack
    99
    10 from struct import *
    11 
    12 def parse_netstumbler(filename):
    13   fh = open(filename,'rb')
    14  
     10def parse_netstumbler(fh):
    1511  def get_int32(size=1):
    1612    v = unpack('<' + 'i'*size,fh.read(4*size))
     
    4339    return v[0] if size == 1 else v
    4440 
     41  def get_mac():
     42    return ':'.join(["%02X" % x for x in unpack('BBBBBB',fh.read(6))])
     43
    4544  data = {}
    4645 
     
    5655    ap["SSIDLength"] = SSIDLength
    5756    ap["SSID"] = get_char(SSIDLength)
    58     ap["BSSID"] = map(hex,unpack('BBBBBB',fh.read(6)))
     57    ap["BSSID"] = get_mac()
    5958    ap["MaxSignal"] = get_int32()
    6059    ap["MinNoise"] = get_int32()
     
    6867    DataCount = get_uint32()
    6968    ap["DataCount"] = DataCount
    70     ap["measurement"] = []
     69    ap["measurements"] = []
    7170    for c in range(0,DataCount):
    7271      ms = {}
     
    7574      ms["Noice"] = get_int32()
    7675      LocationSource = get_int32()
    77       ms["Location Source"] = LocationSource
     76      ms["LocationSource"] = LocationSource
    7877      if LocationSource == 1:
    7978        ms["Latitude"] = get_double()
     
    8584        ms["MagVariation"] = get_double()
    8685        ms["Hdop"] = get_double()
    87       ap["measurement"].append(ms)
     86      ap["measurements"].append(ms)
    8887    NameLength = get_uint8()
    8988    ap["NameLength"] = NameLength
     
    104103  return data
    105104
    106 print parse_netstumbler(sys.argv[1])
     105if __name__ == '__main__':
     106  import sys
     107  import pprint
     108  pp = pprint.PrettyPrinter(indent=2)
     109  pp.pprint(parse_netstumbler(open(sys.argv[1],'r')))
Note: See TracChangeset for help on using the changeset viewer.