Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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!

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.