import pcapy
import struct
+import pyiw
+import threading
+
iface = 'wlan0'
+wlan = pyiw.WirelessInterface(iface)
import time
pc = pcapy.open_live(iface, max_bytes, promiscuous, read_timeout)
+channel_hop = [ 30.0 , False ]
+
+def channel_change ( ) :
+ try :
+ wlan["channel"] = ( wlan["channel"] ) % 12 + 1
+ except pyiw.error, error:
+ print "PYIW error : %s" % error
+ else :
+ if channel_hop[0] :
+ channel_hop[1] = threading.Timer( channel_hop[0] , channel_change )
+ channel_hop[1].start()
+
+
def parse_radiotap( radiotap , it_present ) :
fields = []
frame_subtype = name
break
else :
- print "ERROR : unknown CTL subtype %s" % ( frame_ctl & 0xf0 , )
- return
+ if frame_ctl & 0xf0 == 144 :
+ frame_subtype = "CF_END_ACK"
+ elif frame_ctl & 0xf0 == 128 :
+ frame_subtype = "UNKNOWN_1"
+ else :
+ print "ERROR : unknown CTL subtype %s" % ( frame_ctl & 0xf0 , )
+ return
elif frame_type == "DATA" :
_subtype = []
sequence = ( -1 , -1 )
- if frame_type == "DATA" :
+ if frame_type == "DATA" and pcktlen > 6 :
maclist.append( mac_fmt % struct.unpack( mac_str , payload[pointer:pointer+6] ) )
pointer += 6
pcktlen -= 6
curtime = time.time()
if curtime - tstamp > max_time :
+ channel_hop[0] = 0
raise CaptureEnd( "Neighborhoud scan completed" )
+if channel_hop[0] :
+ channel_hop[1] = threading.Timer( channel_hop[0] , channel_change )
+ channel_hop[1].start()
+
+
packet_limit = -1 # infinite
try :
pc.loop( packet_limit , dealWithPacket )
except CaptureEnd , ex :
print "FINISED : %s" % ex
except Exception , ex :
+ channel_hop[0] = 0
print "ERROR : %s" % ex
logfile.close()