0

I have problems i'cant run this script I tried creating an ICMP network sniffer as follows:

import socket
import os

host = '192.168.1.9'

if os.name == "nt":
   socket_protocol = socket.IPPROTO_IP
else:
   socket_protocol = socket.IPPROTO_ICMP
   sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW,socket_protocol)
   sniffer.bind((host, 0))   

   sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

if os.name == "nt":

  sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
  print sniffer.recvfrom(656565)

if os.name == "nt":

  sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)



Traceback (most recent call last):
File "exampl.py", line 11, in <module>
sniffer.bind((host, 6000))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address

What can I do to prevent this error?

1 Answer 1

1
socket.error: [Errno 99] Cannot assign requested address

What can I do to prevent this error?

The name of errno 99 is defined by

#define EADDRNOTAVAIL   99      /* Cannot assign requested address */

and man bind says:

   EADDRNOTAVAIL
          A  nonexistent  interface was requested or the requested address
          was not local.

This suggests trying with a local address, and indeed there's no more error with:

host = 'localhost'
Sign up to request clarification or add additional context in comments.

2 Comments

Why would he have to change the address to local host that is not the objective
You haven't recognized that the objective is to prevent this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.