I tried creating an ICMP network sniffer as follows:
import socket,os
host="192.168.1.7"
#create a socket protocol
socket_protocol=socket.IPPROTO_ICMP
sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket_protocol)
sniffer.bind((host, 6677))
sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
print(sniffer.recvfrom(65565))
"192.168.1.7" is a local address of another PC connected to the router that my wireless network interface is connected to. I obtained this address doing a wireshark capture.
when the codes are execute, I recieve the following error
Traceback (most recent call last):
File "/root/test.py", line 18, in <module>
sniffer.bind((host, 6677))
socket.error: [Errno 99] Cannot assign requested address
When I use my wireless network card interface local ip address ("192.168.1.9"), everything goes fine.
What can I do to prevent this error...Thanks in advance!