Skip to content

Instantly share code, notes, and snippets.

@nevdull77
Created April 13, 2014 22:34
Show Gist options
  • Select an option

  • Save nevdull77/10605115 to your computer and use it in GitHub Desktop.

Select an option

Save nevdull77/10605115 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from scapy.all import *
from datetime import datetime
import sys
import time
found = {}
def sniffmgmt(p):
stamgmtstypes = (0, 2, 4)
if p.haslayer(Dot11) and p.type == 0 and p.subtype == 0x08 and hasattr(p, 'info'):
ssid = ( len(p.info) > 0 and p.info != "\x00" ) and p.info or '<hidden>'
probe = { "ssid": ssid, "cli": p.addr2, "lastseen" : datetime.fromtimestamp(time.time()).isoformat() }
key = "%s_%s" % (ssid, p.addr2)
found[key] = probe
print(probe)
if len(sys.argv) < 2:
print("usage: sniff.py <iface>")
sys.exit(-1)
sniff(iface=sys.argv[1], prn=sniffmgmt)
# when ctrl + c is pressed, write results to disk
with open('output.txt', 'a') as f:
f.write(",".join(["ssid", "cli", "lastseen"]) + "\r\n")
for key in found:
f.write(",".join(['"%s"' % x for x in [ found[key]['ssid'], found[key]['cli'], found[key]['lastseen']]]) + "\r\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment