Skip to content

Instantly share code, notes, and snippets.

@securitytube
Created April 2, 2013 12:49
  • Star 42 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save securitytube/5291959 to your computer and use it in GitHub Desktop.
WLAN SSID Sniffer in Python using Scapy
#!/usr/bin/env python
from scapy.all import *
ap_list = []
def PacketHandler(pkt) :
if pkt.haslayer(Dot11) :
if pkt.type == 0 and pkt.subtype == 8 :
if pkt.addr2 not in ap_list :
ap_list.append(pkt.addr2)
print "AP MAC: %s with SSID: %s " %(pkt.addr2, pkt.info)
sniff(iface="mon0", prn = PacketHandler)
@mwatts7222
Copy link

Very nice.

@lifeofpentester
Copy link

Hi, I wanted to know how I can leverage Scapy to tell me the Encryption type as well (WEP, WPA, WPA2, WPS Enabled). I am doing some research on Wifi security and I really need to code something using python and scapy that would tell me the ENC type. Can you help please?

@uforek
Copy link

uforek commented Jul 21, 2014

Quick question...

Would checking the packet for the Dot11Beacon layer be the same as checking the packet type for 0x00 and subtype for 0x08, as in your script above?

I wrote a similar script where I was getting strange results on occasion and unfortunately never logged the complete packet to debug the issue, but it appeared as the value in the packet's info var would sometimes appear empty or with unexpected ascii chars.

@adamziaja
Copy link

If you want to sniff SSID then why you only catch beacon packets? Correct version https://github.com/adamziaja/python/blob/master/ssid_sniffer.py and probe request sniffer https://github.com/adamziaja/python/blob/master/probe_request_sniffer.py . Also please try keep your script running a long period of time and look your cpu/mem... all packets will be in memory.

@adamziaja
Copy link

@uforek: yes, subtype 8 is beacon

@vck
Copy link

vck commented Feb 14, 2015

is there some spesification for the network interface ? it didn't works well on mine

@ajdumanhug
Copy link

I'm having a problem with my sniff().
I used from scapy import * instead of scapy.all import *

@chaya2090
Copy link

hello evryone,
I am using mininet-wifi to send dot11 packets from station1 to station 2 but I am not able to send.May b I am making mistake in send and sniff commands...Please suggest

@lucascouto
Copy link

Thank you, very much!

@dickkaas
Copy link

Hello,

I'am rather new by using python (lotst ofe experience with other languages). I bougth a raspberry and know tries to find out if I can use my Pi for notifying if a dedicated person is in the neighbouhood. I.e. by detecting Wifi, bluetooth or other specifc signal (also for automatic opening doors; get ligths on etc.)
I loaded the code and tried to run the application.
it just gave me the error it could not find scapy
--> I did install the scapy modules by PIP
What did probably go wrong?

Dick

@MushuDG
Copy link

MushuDG commented May 9, 2020

Hello,

Thanks for this script, I'm using it for a personal project!

I don't know if it's currently obsolete or not, the if condition which tests the type and the subtype never returns positive value to me. So I changed if pkt.haslayer (Dot11): so that it becomes if pkt.haslayer (Dot11ProbeReq):

I was then able to delete the if type && subtype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment