Wifi sniffer capability; often asked for, never delivered?

  • Hello!

    Covid -19 has given me time to ressurect my embedded experiments!

    I've noted that there are a number of esp32 solutions to "promiscuous" wifi sniffing (mostly in "C"), indeed Zerynth provide a "compiled python solution" that can be targeted to the pycom modules. Over the years there have been requests for this facility in Pycom; so my question is, "Does WIFI sniffing exist, will it ever exist? If it does where is the documentation, examples etc. For sure a "work round" solution can be created that uses a slave esp32 running alongside a Pycom module, but this is not very elegant.

    I'm keen to have an answer, please.

    Many thanks in advance.

  • administrators

    @drgdhorler We added experimental support for this. Below is some example code to capture MAC addresses.

    from network import WLAN
    import ubinascii
    def pack_cb(pack):
        mac = bytearray(6)
        pk = wlan.wifi_packet()
        control = pk.data[0]
        subtype = (0xF0 & control) >> 4
        type = 0x0C & control
        #print("Control:{}, subtype:{}, type:{}".format(control, subtype, type))
        if subtype == 4:
            for i in range (0,6):
                mac[i] = pk.data[10 + i]
            print ("Wifi Node with MAC: {}".format(ubinascii.hexlify(mac)))
    wlan = WLAN(mode=WLAN.STA, antenna=WLAN.EXT_ANT)
    wlan.callback(trigger=WLAN.EVENT_PKT_MGMT, handler=pack_cb)

Log in to reply

Pycom on Twitter