Last active
October 3, 2017 13:43
-
-
Save singe/029076292034147823fcdfdc5ffdadde to your computer and use it in GitHub Desktop.
Display nearby wifi network SSIDs, BSSIDs and connected clients.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# by @singe | |
# | |
# Invoke it like you would tshark e.g. | |
#./wifi-hierarchy.py -r file.pcap | |
#./wifi-hierarchy.py -i en0 | |
# | |
# Dependencies, tshark in your path and python3 | |
from subprocess import getoutput | |
from sys import argv | |
switch = argv[1] | |
if switch not in ["-r","-i"]: | |
exit() | |
if switch == "-i": #Add some stuff for live capture | |
switch = "-a duration:2 -Ii" | |
cap = argv[2] | |
fcs='' #Frame Check Sequence check | |
if getoutput(f"tshark {switch} {cap} -c1 -Y wlan.fcs")!='': | |
fcs="-Y wlan.fcs.status==1" | |
ssids = [i for i in getoutput(f"tshark {switch} {cap} -T fields -e wlan_mgt.ssid {fcs} 2>/dev/null|sort -u").split('\n') if i != ''] | |
for ssid in ssids: | |
print(f"SSID: {ssid}") | |
bssids = [i for i in getoutput(f"tshark {switch} {cap} -T fields -e wlan.bssid -Y 'wlan_mgt.ssid==\"{ssid}\"' 2>/dev/null|sort -u").split('\n') if i != 'ff:ff:ff:ff:ff:ff'] | |
for bssid in bssids: | |
print(f" BSSID {bssid}") | |
stas = getoutput(f"tshark {switch} {cap} -T fields -e wlan.sa -Y 'wlan.sa!={bssid} && wlan.bssid=={bssid}' 2>/dev/null|sort -u").split('\n') | |
for sta in stas: | |
print(f" STA {sta}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example using the cap from https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=get&target=Network_Join_Nokia_Mobile.pcap
./wifi-hierarchy.py -r Network_Join_Nokia_Mobile.pcap
SSID: martinet3
BSSID 00:01:e3:41:bd:6e
STA 00:01:e3:42:9e:2b
STA 00:15:00:34:18:52
STA 00:16:bc:3d:aa:57