Search code examples
pythonpython-2.7socketsscapygetaddrinfo

Scapy import error 'socket.gaierror: [Errno 11001] getaddrinfo failed'


Im trying to install Scapy on windows 10, python 2.7.11, and stuck on this error:

>>> from scapy.all import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\tools\python\lib\site-packages\scapy\all.py", line 25, in <module>
    from scapy.route import *
  File "C:\tools\python\lib\site-packages\scapy\route.py", line 182, in <module>
    _betteriface = conf.route.route("0.0.0.0", verbose=0)[0]
  File "C:\tools\python\lib\site-packages\scapy\route.py", line 150, in route
    aa = atol(a)
  File "C:\tools\python\lib\site-packages\scapy\utils.py", line 400, in atol
    except socket.error:
socket.gaierror: [Errno 11001] getaddrinfo failed

What does it mean?


Solution

  • As stated in the python 2.7 documentation, this error is thrown either by the getaddrinfo() or getnameinfo() function.
    Judging by the stack trace, the scapy module tries to initialize a socket during its import and the port number is invalid (we can see the atol function being called, which convert a string to an integer).
    It is unclear what the real issue is. However, you can try the following things:

    • Make sure you have the right version of python and scapy. I suggest that you install scapy from pip, and maybe use a virtual environment to run your script.
    • You can also try to compile scapy from source, or check the issue section in github to see if your problem is actually a known problem being worked on.
    • Maybe scapy tries to initialize a raw socket (i don't know why they would, but its worth a try), which requires admin privileges. Try running your script as admin.

      Hope this helps