-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot11sniffer.py
94 lines (70 loc) · 2.02 KB
/
dot11sniffer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/python2
import time
from threading import *
import signal
import sys
import netifaces
from sniffer_module import *
from dblib.dbSender import *
# globals
shouldQuit = None
otherThread = None
sender = Sender()
hostname = ""
# signal handler
def sigintHandler(signum, frame):
print("Quitting uncleanly")
sys.exit()
# search for interfaces until we found a monitor interface
def findIface():
chosenIface = None
while chosenIface is None:
ifaces = netifaces.interfaces()
for iface in ifaces:
if iface[:3] == 'mon':
chosenIface = iface
return chosenIface
# gets hostname for computer
def loadHostname():
global hostname
hostnameFile = open("/etc/hostname", "r")
hostname = hostnameFile.readline()
hostnameFile.close()
hostname = hostname[:-1]
# send the contents of the list
def sendData(otherThread):
sender.clear()
# lock for clearing
otherThread.listLock.acquire()
# add each of the packets to the list
for mac in otherThread.devices:
sender.add(mac, hostname, otherThread.devices[mac][0], otherThread.devices[mac][1])
# clear out the device buffer
otherThread.devices = {}
otherThread.listLock.release()
# and send off the data
sender.send()
def main():
# register signal handler and then sleep until we get a response
signal.signal(signal.SIGINT, sigintHandler)
# init the processing thread
shouldQuit = False
listLock = Lock()
otherThread = ProcessingThread(listLock, shouldQuit)
# find monitor inferaces
print("Looking for monitor interfaces...")
chosenIface = findIface()
print("Found Interface: " + chosenIface)
# get the hostname
loadHostname()
print("Hostname: " + hostname)
# start the other thread to start sniffing
otherThread.start()
# sit and spin while the other thread does things
while True:
print("sending off data")
sendData(otherThread)
time.sleep(15)
# run main
if __name__ == "__main__":
main()