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
99
100
|
#!/usr/bin/env python
from sys import argv, exit, stderr
import os
import os.path
import xml.etree.ElementTree
class AccessPoint:
def __init__(self):
self.cloaked = False
self.essid = None
self.encryption = set()
self.packets = 0
self.beaconrate = []
self.bssid = set()
self.strength = []
self.manufacturer = set()
self.channel = set()
def __cmp__(self, other):
self = sum(self.strength) / len(self.strength)
other = sum(other.strength) / len(other.strength)
if self > other:
return 1
elif self < other:
return -1
else:
return 0
def __str__(self):
out = ""
if self.essid is None:
out += "<cloaked>\n"
else:
out += self.essid + "\n"
out += "Encryption: %s\n" % ", ".join(self.encryption)
out += "Manufacturer: %s\n" % ", ".join(self.manufacturer)
out += "BSSID: %s\n" % ", ".join(self.bssid)
out += "Channel: %s\n" % ", ".join(self.channel)
out += "Packets: %d" % self.packets
if len(self.beaconrate) > 0:
out += "\nBeacon Rate: %d" % (sum(self.beaconrate) / len(self.beaconrate))
if len(self.strength) > 0:
out += "\nStrength: %d" % (sum(self.strength) / len(self.strength))
return out
def processDir(directory):
for entry in os.listdir(directory):
entry = os.path.join(directory, entry)
if os.path.isdir(entry):
processDir(entry)
elif os.path.splitext(entry)[1] == ".netxml":
processFile(entry)
accessPoints = {}
def processFile(xmlfile):
root = xml.etree.ElementTree.parse(xmlfile).getroot()
for network in root.findall("wireless-network"):
ap = AccessPoint()
essid = network.find("SSID/essid")
if essid is None:
continue
if essid.get("cloaked", "false") == "true":
ap.essid = None
else:
ap.essid = essid.text
if ap.essid is not None and ap.essid in accessPoints:
ap = accessPoints[ap.essid]
for encryption in network.findall("SSID/encryption"):
ap.encryption.add(encryption.text)
packets = network.findtext("SSID/packets")
if packets is not None:
ap.packets += int(packets)
strength = network.findtext("snr-info/max_signal_dbm")
if strength is not None:
ap.strength.append(int(strength))
beaconrate = network.findtext("SSID/beaconrate")
if beaconrate is not None:
ap.beaconrate.append(int(beaconrate))
ap.bssid.add(network.findtext("BSSID"))
ap.manufacturer.add(network.findtext("manuf"))
ap.channel.add(network.findtext("channel"))
accessPoints[ap.essid] = ap
if len(argv) < 2:
print >> stderr, "Usage: %s DIRECTORIES... | FILES..." % argv[0]
exit(-1)
for arg in argv[1:]:
if not os.path.exists(arg):
print >> stderr, "%s does not exist." % arg
elif os.path.isfile(arg):
processFile(arg)
elif os.path.isdir(arg):
processDir(arg)
accessPoints = sorted(accessPoints.values(), reverse=True)
for ap in accessPoints:
print ap
print
|