Search code examples
pythonpython-3.xscapy

Scapy: Undefined variable 'Dot11Beacon' and 'Dot11Elt'


I am trying to do a simple wifi sniffer using scapy, on Ubuntu, but I encountered the following problems when I try to run the application:

Undefined variable 'Dot11Beacon' 
Undefined variable 'Dot11Elt'

For now I try to run the code in this following tutorial: https://www.shellvoide.com/python/how-to-code-a-simple-wireless-sniffer-in-python/

and it simple doesn't work because of the above errors. I am using Python 3 and the latest version of scapy, installed through pip.

Even if it's the same as in the tutorial, here are the parts of code I am using:

from scapy.all import *

sniff(iface=interface, prn=process_packet)

def process_packet(pak):
    if pak.haslayer(Dot11Beacon):
        if pak.getlayer(Dot11).addr2 not in F_bssids:
            F_bssids.append(pak.getlayer(Dot11).addr2)
            ssid = pak.getlayer(Dot11Elt).info
            if ssid == '' or pak.getlayer(Dot11Elt).ID != 0:
                print("Hidden Network Detected")
            print("Network Detected: %s" % (ssid))

Solution

  • You are having the same issue than https://stackoverflow.com/a/53402404/5459467 The same applies in PyCharm and Visual studio. Have a look at my answer there.

    The workaround is to import whatever you need from their related scapy file, without using all. It is cleaner but longer to do. Or you can use "add an exception" in your IDE, if you’re not looking for something clean.