forked from hazcod/ISIS-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_networks.py
executable file
·98 lines (86 loc) · 2.19 KB
/
check_networks.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
97
98
#! /usr/bin/python
import subprocess
import socket
import urllib2
import os
from database import *
manufac_url = "http://api.macvendors.com/"
def main():
scan()
def scan():
allinfo= subprocess.check_output(["sudo", "iwlist", "wlan0","scan"])
tempfile= open("/tmp/ssid","wb")
tempfile.write(allinfo)
tempfile.close()
networks=[]
network={}
tempfile= open ("/tmp/ssid", "r")
Error404=False
for line in tempfile:
if "Address" in line:
lineparts= line.split(":", 1)
MAC= lineparts[1].rstrip().lstrip()
network={"MAC": MAC}
networks.append(network)
try:
network['manufac'] = urllib2.urlopen(manufac_url + network['MAC']).read()
except:
Error404=True
network['manufac']=""
if "Channel:" in line:
lineparts=line.split(":")
channel= lineparts[1].rstrip()
network["channel"]= channel
if "Quality" in line:
lineparts=line.split("=")
lineparts2=lineparts[1].split("/")
quality=lineparts2[0]
network["quality"]=quality
if "Encryption key" in line:
lineparts=line.split(":")
if lineparts[1].rstrip()=="off":
network["enc"]="open"
if "ESSID" in line:
lineparts=line.split(":")
SSID=lineparts[1].rstrip()
network["SSID"]= SSID
if "WPA" in line:
lineparts= line.split("/")
encPart=lineparts[-1].rstrip();
if "Authentication Suites" in line:
lineparts=line.split(":")
encPart+=lineparts[1].rstrip()
network["enc"]= encPart
if "enc" not in network:
network["enc"]= "WEP"
query= "delete from ap_info where caption='"
query+=socket.gethostname()
query+="';"
executequery(query)
query="insert into ap_info(wifi_network,caption,quality,channel,mac_adress,encryption,manufac,last_updated) values "
for network in networks:
query+='('
query+=network["SSID"]
query+=',"'
query+=socket.gethostname()
query+='",'
query+=network["quality"]
query+=','
query+=network["channel"]
query+=',"'
query+=network["MAC"]
query+='","'
query+=network["enc"]
query+='","'
query+=network['manufac']
query+='",'
query+="now()"
query+="),\n"
query=query[:-2]
query+=";"
executequery(query)
os.remove ("/tmp/ssid")
if Error404:
raise Exception ("couldn't resolve manufacturer")
if __name__ == "__main__":
main()