You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When invoking AsyncSniffer with an interface that doesn't exist, it causes an Exception in AsyncSniffer thread. I've discovered this by accident, as my project's code was trying to invoke the sniffing process with an incorrect interface name. An easy fix for me was to check the interface name and in doing so preventing this. For example, when trying to sniff packets on a monitoring interface, which hasn't yet been created (e.q. wlan0mon), this error occurs. Also, another solution for this could be to use a custom exception hook.
Running the example I've provided creates the AsyncSniffer thread and starts executing it. The thread blocks for a moment and raises an exception, which then bubbles up and is reported as an error (it's printed out). The failure in the thread does not impact the main thread, but the code after doesn't know that the capture of packets has failed. Ideally, I would like to know that the sniffing has failed, so I can stop my own program instead of having my program in an idle state.
Scapy version
2.5.0
Python version
3.11.4
Operating system
Linux 5.15.44-Re4son-v8l+
Additional environment information
The program was ran on Raspberry Pi 4.
How to reproduce
I can reproduce this by simply running this script:
It would be preferable if the unexpected and unhandled Exception doesn't occur. You could maybe check if the given interface is available (exists) during the creation of the AsyncSniffer and return some sort of indicator that the provided interface doesn't exist. This could prevent this sort of error.
Related resources
Exception in thread AsyncSniffer:
Traceback (most recent call last):
File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 1171, in _run
sniff_sockets[_RL2(iface)(type=ETH_P_ALL, iface=iface,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 499, in __init__
set_promisc(self.ins, self.iface)
File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 179, in set_promisc
mreq = struct.pack("IHH8s", get_if_index(iff), PACKET_MR_PROMISC, 0, b"")
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 399, in get_if_index
return int(struct.unpack("I", get_if(iff, SIOCGIFINDEX)[16:20])[0])
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/scapy/arch/unix.py", line 42, in get_if
return ioctl(sck, cmd, struct.pack("16s16x", iff.encode("utf8")))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 19] No such device
The text was updated successfully, but these errors were encountered:
Brief description
When invoking
AsyncSniffer
with an interface that doesn't exist, it causes anException
inAsyncSniffer
thread. I've discovered this by accident, as my project's code was trying to invoke the sniffing process with an incorrect interface name. An easy fix for me was to check the interface name and in doing so preventing this. For example, when trying to sniff packets on a monitoring interface, which hasn't yet been created (e.q. wlan0mon), this error occurs. Also, another solution for this could be to use a custom exception hook.Running the example I've provided creates the
AsyncSniffer
thread and starts executing it. The thread blocks for a moment and raises an exception, which then bubbles up and is reported as an error (it's printed out). The failure in the thread does not impact the main thread, but the code after doesn't know that the capture of packets has failed. Ideally, I would like to know that the sniffing has failed, so I can stop my own program instead of having my program in an idle state.Scapy version
2.5.0
Python version
3.11.4
Operating system
Linux 5.15.44-Re4son-v8l+
Additional environment information
The program was ran on Raspberry Pi 4.
How to reproduce
I can reproduce this by simply running this script:
The
Exception
occurs afterjoin()
.Actual result
Unhandled
Exception
occurs.Expected result
It would be preferable if the unexpected and unhandled
Exception
doesn't occur. You could maybe check if the given interface is available (exists) during the creation of theAsyncSniffer
and return some sort of indicator that the provided interface doesn't exist. This could prevent this sort of error.Related resources
The text was updated successfully, but these errors were encountered: