-
Notifications
You must be signed in to change notification settings - Fork 1
/
scan_vulnerable_aps.py
executable file
·54 lines (49 loc) · 1.7 KB
/
scan_vulnerable_aps.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
#!/usr/bin/env python
import errno
import sys
import types
from mac2defaults import default_key, default_ssid
try:
import pythonwifi.flags
from pythonwifi.iwlibs import Wireless, Iwrange, getNICnames
except ImportError:
sys.stderr.write("Error: missing pythonwifi module\n")
sys.exit(1)
def print_probable_keys(wifi):
""" Print the probable keys
"""
# "Check if the interface could support scanning"
try:
iwrange = Iwrange(wifi.ifname)
except IOError, (error_number, error_string):
sys.stderr.write("%-8.16s Interface doesn't support scanning.\n\n" % (
wifi.ifname))
else:
try:
results = wifi.scan()
except IOError, (error_number, error_string):
if error_number == errno.EPERM:
sys.stderr.write("Permission denied. Did you run the program as root?\n")
else:
sys.stderr.write(
"%-8.16s Interface doesn't support scanning : %s\n\n" %
(wifi.ifname, error_string))
else:
for ap in results:
if "Master" == ap.mode:
defaultkey = default_key(ap.bssid)
defaultessid = default_ssid(ap.bssid)
if ap.essid[-4:] == defaultessid:
print "* %s: %s" % (ap.essid, defaultkey)
else:
print "- %s: %s" % (ap.essid, defaultkey)
def main():
# if only program name is given, print usage info
if len(sys.argv) == 1:
ifname = "wlan0"
else:
ifname = sys.argv[1]
wifi = Wireless(ifname)
print_probable_keys(wifi)
if __name__ == "__main__":
main()