summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2011-12-05 16:27:19 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2011-12-05 16:27:19 -0500
commit354b8ee4d66f29067bd3dbdaaa0d64f6d3bfb675 (patch)
tree808371dc6af670a4181ace45f72179a2dfc7b6ac
parentActually stop wpa_supplicant properly. (diff)
downloadwifi-monitoring-scripts-354b8ee4d66f29067bd3dbdaaa0d64f6d3bfb675.tar.xz
wifi-monitoring-scripts-354b8ee4d66f29067bd3dbdaaa0d64f6d3bfb675.zip
Add kismet parsing script.
-rwxr-xr-xparse-kismet.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/parse-kismet.py b/parse-kismet.py
new file mode 100755
index 0000000..c66c123
--- /dev/null
+++ b/parse-kismet.py
@@ -0,0 +1,97 @@
+#!/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()
+ 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 += "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"))
+ 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
+