0

I use sniff() function in scapy for sniff packets on several interfaces. I used this function in the same way as it is written in the documentation:

inet_faces=['ens33', 'ens38']
sniff(iface=int_faces)

This code is equivalent to this code, as it is written in the documentation

sniff(['ens33', 'ens38'])

But instead of it working, I get these errors:

> Exception in thread Thread-1:
> Traceback (most recent call last):
>  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
>    self.run()
>  File "/usr/lib/python3.6/threading.py", line 864, in run
>    self._target(*self._args, **self._kwargs)
>  File "/home/user/Desktop/crs_wrk/z2/switch.py", line 124, in sniff_packets
>    sniff(iface=['ens33', 'ens38'])
>  File "/usr/local/lib/python3.6/dist-packages/scapy/sendrecv.py", line 1263, in sniff
>    sniffer._run(*args, **kwargs)
>  File "/usr/local/lib/python3.6/dist-packages/scapy/sendrecv.py", line 1128, in _run
>    **karg)] = iface
>  File "/usr/local/lib/python3.6/dist-packages/scapy/arch/linux.py", line 501, in __init__
>    set_promisc(self.ins, self.iface)
>  File "/usr/local/lib/python3.6/dist-packages/scapy/arch/linux.py", line 181, in set_promisc
>    mreq = struct.pack("IHH8s", get_if_index(iff), PACKET_MR_PROMISC, 0, b"")
>  File "/usr/local/lib/python3.6/dist-packages/scapy/arch/linux.py", line 401, in get_if_index
>    return int(struct.unpack("I", get_if(iff, SIOCGIFINDEX)[16:20])[0])
>  File "/usr/local/lib/python3.6/dist-packages/scapy/arch/common.py", line 65, in get_if
>    return ioctl(sck, cmd, struct.pack("16s16x", iff.encode("utf8")))
>AttributeError: 'list' object has no attribute 'encode'

Аmong all these lines, the key lines is this:

>File "/home/user/Desktop/crs_wrk/z2/switch.py", line 124, in sniff_packets
>    sniff(iface=['ens33', 'ens38'])
> AttributeError: 'list' object has no attribute 'encode'

So, this code causes the same errors:

sniff(iface=['ens33'])

But this code works correct:

sniff(iface='ens33')

The error lies in the fact that I am passing a list, although the documentation says that this can be done. Please help me.

DYZ
  • 55,249
  • 10
  • 64
  • 93

0 Answers0