read_timeout = 100 # in milliseconds
pc = pcapy.open_live(iface, max_bytes, promiscuous, read_timeout)
-import ieee80211
+from ieee80211 import *
import time
tstamp = time.time()
discovered = []
-def dealWithPacket ( hdr , data ) :
-
- if hdr.getlen() != hdr.getcaplen() :
- print "Error in header : %d vs. %d" % ( hdr.getlen() , hdr.getcaplen() )
- return
- if len(data) != hdr.getlen() :
- print "Data lenght does not match"
- return
-
- it_version , it_len , it_present = struct.unpack("<Bxhl",data[:8])
- if it_version != 0 :
- print "Bad version (%s), it is probably not radiotap header" % it_version
- return
- if it_len <= 0 :
- print "Bad length on radiotap header"
- return
-
- radiotap = data[:it_len]
- payload = data[it_len:]
+def parse_radiotap( radiotap , it_present ) :
- format , padstr = "<" , ""
fields = []
+ format , padstr = "<" , ""
for name,bit,fmt,pad in ratiotap_header_bits :
# What about 'it_present & ( 0x1 << bit )' ??
if it_present & pow(2,bit) == pow(2,bit) :
fields.append( name )
if fmt == "hh" :
fields.append( "CHANNEL_BITMAP" )
+ format += fmt
if pad :
padstr += "x"
- format += fmt
- values = struct.unpack(format+padstr,radiotap[8:])
+ values = struct.unpack(format+padstr,radiotap])
+
+ radio_hdr = {}
+ for i in range(len(fields)) :
+ radio_hdr[fields[i]] = values[i]
flags = []
for name,value in radiotap_flags :
- if values[1] & value == value :
+ if radio_hdr['FLAGS'] & value == value :
flags.append( name )
+ radio_hdr['_flags'] = flags
+ if radio_hdr['FLAGS'] != 16 and radio_hdr['FLAGS'] != 18 :
+ # 16 - FCS
+ # 18 - SHORTPRE , FCS
+ print 'WARNING : Unexpected flags : (%s) %s' % ( radio_hdr['FLAGS'] , " , ".join( flags ) )
channel = []
for name,value in channel_flags :
- if values[4] & value == value :
+ if radio_hdr['CHANNEL_BITMAP'] & value == value :
channel.append( name )
+ if radio_hdr['CHANNEL_BITMAP'] != 160 and radio_hdr['CHANNEL_BITMAP'] != 192 :
+ # 160 - CCK , 2GHZ
+ # 192 - OFDM , 2GHZ
+ print 'WARNING : Unexpected channel flags : (%s) %s' % ( radio_hdr['CHANNEL_BITMAP'] , " , ".join( channel ) )
+ radio_hdr['_channel_bitmap'] = channel
+
+ return radio_hdr
+
+
+def dealWithPacket ( hdr , data ) :
+
+ if hdr.getlen() != hdr.getcaplen() :
+ print "Error in header : %d vs. %d" % ( hdr.getlen() , hdr.getcaplen() )
+ return
+ if len(data) != hdr.getlen() :
+ print "Data lenght does not match"
+ return
+
+ it_version , it_len , it_present = struct.unpack("<Bxhl",data[:8])
+ if it_version != 0 :
+ print "Bad version (%s), it is probably not radiotap header" % it_version
+ return
+ if it_len <= 0 :
+ print "Bad length on radiotap header"
+ return
+
+ radio_hdr = parse_radiotap( data[8:it_len] , it_present )
+ if not radio_hdr :
+ return
+
+ payload = data[it_len:]
+
pointer = 0
pcktlen = len(payload)