-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.py
78 lines (58 loc) · 2.29 KB
/
project.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
#!/usr/bin/env python
import sys,MySQLdb
import schedule
from scapy.all import *
def banner():
print "##################################"
print " Finding AP and mac"
print "####################################"
apmac=set()
clientmac=set()
def handler(pkt):
if pkt.haslayer(Dot11ProbeReq):
if pkt.info:
value=pkt.addr2+"---"+pkt.info
if value not in clientmac:
clientmac.add(value)
#print "client MAC "+pkt.addr2 +" "+"SSID :"+pkt.info
currenttime=time.ctime()
conn_time=re.findall(r'([0-9]{2}\:[0-9]{2}\:[0-9]{2})',currenttime)
connectiontime=str(conn_time[0])
db=MySQLdb.connect("localhost","root","raspberry","Probrequest")
cursor=db.cursor()
db=MySQLdb.connect("localhost","root","raspberry","Probrequest")
cursor=db.cursor()
x=pkt.notdecoded
try:
signalstrength=struct.unpack('>b',x[-2:-1])[0] # RSSI bit 16 of radiotapheader
sql1="insert into clientinfo(clientmac,signalstrengthdbm,connectiontime,SSID) values('%s','%d','%s','%s');"%(pkt.addr2,signalstrength,currenttime,pkt.info)
cursor.execute(sql1)
db.commit()
print "client MAC "+pkt.addr2 +" "+"SSID :"+pkt.info
print connectiontime+" "+str(signalstrength)+ "dbm"
except IndexError:
print " Index error out of range"
db.close()
def read():
db=MySQLdb.connect("localhost","root","raspberry","Probrequest")
cursor=db.cursor()
sql="select clientmac,SSID from clientinfo;"
cursor.execute(sql)
results=cursor.fetchall() #reading from databases
if not results:
print " Databases is empty"
else:
print " *****************************"
for row in results:
client=row[0]
ssid=row[1]
data=client+"---"+ssid
if data not in apmac:
apmac.add(data)
print data
#print data
db.close()
banner()
read()
#sniff(iface="mon0",count=int(sys.argv[1]),prn=handler)
sniff(iface="mon0",count=5000,prn=handler)