forked from G4lile0/Heimdall-WiFi-Radar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phatsniffer.py
executable file
·96 lines (77 loc) · 2.38 KB
/
phatsniffer.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
95
96
#!/usr/bin/python
import json
import serial
import time
#import RPi.GPIO
vendors = {}
def read_vendors(filename):
file = open(filename, 'r')
for line in file:
prefix, vendor = line.rstrip().split('\t')
vendors[prefix] = vendor
def send_command(command):
comm = serial.Serial('/dev/ttyUSB0', 115200)
if comm.isOpen():
comm.close()
comm.open()
comm.flushInput()
comm.write(command+'\n')
time.sleep(0.1)
return comm.readline()
def create_fake_beacon(channel, ssid):
return send_command('fake_beacon %d %s' % (channel, ssid))
def remove_fake_beacon(channel):
return send_command('fake_beacon %d' % channel)
def get_sniffer_data():
data = json.loads(send_command('print_all').decode('utf-8', 'ignore').encode('utf-8'))
# data = json.loads(send_command('pa1').decode('utf-8', 'ignore').encode('utf-8'))
beacons = data['beacons']
clients = data['clients']
for beacon in beacons:
prefix = beacon[0:8]
if prefix in vendors:
beacons[beacon]['vendor'] = vendors[prefix]
for client in clients:
beacon = clients[client]['beacon']
if beacon in beacons:
clients[client]['ssid'] = beacons[beacon]['ssid']
clients[client]['channel'] = beacons[beacon]['channel']
else:
clients[client]['ssid'] = ''
clients[client]['channel'] = ''
prefix = client[0:8]
if prefix in vendors:
clients[client]['vendor'] = vendors[prefix]
return data
def get_sniffer_data1():
data1 = json.loads(send_command('pa1').decode('utf-8', 'ignore').encode('utf-8'))
beacons = data1['beacons']
clients = data1['clients']
for beacon in beacons:
prefix = beacon[0:8]
if prefix in vendors:
beacons[beacon]['vendor'] = vendors[prefix]
for client in clients:
beacon = clients[client]['beacon']
if beacon in beacons:
clients[client]['ssid'] = beacons[beacon]['ssid']
clients[client]['channel'] = beacons[beacon]['channel']
else:
clients[client]['ssid'] = ''
clients[client]['channel'] = ''
prefix = client[0:8]
if prefix in vendors:
clients[client]['vendor'] = vendors[prefix]
return data1
def reset_phat():
# RPi.GPIO.setmode(RPi.GPIO.BCM)
# RPi.GPIO.setup(17,RPi.GPIO.OUT,initial=1)
# RPi.GPIO.setup(27,RPi.GPIO.OUT,initial=1)
# RPi.GPIO.output(17,0)
# time.sleep(0.5)
# RPi.GPIO.output(17,1)
time.sleep(0.5)
# RPi.GPIO.cleanup()
if __name__ == '__main__':
read_vendors('data/vendors.tsv')
print json.dumps(get_sniffer_data(), sort_keys=True, indent=4, separators=(',', ': '))