Search code examples
pythonnetwork-programmingscapy

Scapy will listen on wlan0 but not wlan1 that is set to monitor mode


I have two wireless interfaces, wlan0 and wlan1. I am connected to a raspberry pi on my home network via wlan0 and I am using wlan1 as an access point to collect probe requests.

I set wlan1 into monitor mode (iwconfig shows mode: Master when changed)

subprocess.run(f'ifconfig wlan{interface_id} down', shell=True)
subprocess.run(f'ifconfig wlan{interface_id} mode Monitor', shell=True)
subprocess.run(f'ifconfig wlan{interface_id} up', shell=True)

When running this code to check the card is in monitor (Master) mode it returns true:

def is_card_in_mon_mode(interface_id):
    output = subprocess.Popen(['iwconfig', f'wlan{interface_id}'], stdout=subprocess.PIPE)
    for param in output.stdout:
        if b'Master' in param:
            return True

Then, performing: sniff(iface="wlan1", prn=handle_packet) doesn't access the handle_packet method.

Using sniff(iface="wlan0", prn=handle_packet) does access the handle_packet method, is there any reason it will work on wlan0 but not wlan1?


Solution

  • I'm being dumb. There was no network traffic hence no call back function. Code above works as intended, if anyone else has this issue consider sending packets over that interface and then seeing if anything happens..