Scapy installation fails on osx with dnet import error

前端 未结 5 1216
囚心锁ツ
囚心锁ツ 2020-12-24 08:16

Having trouble installing Scapy and it\'s required dependancies. I have spent some time Googling for a solution but all \'solutions\' seem to affect older versions of Python

5条回答
  •  不知归路
    2020-12-24 08:24

    EDIT (30.10.19)

    Install Scapy

    Scapy's official documentation lists the possible bundles:

    • Default, only Scapy:
      • $ pip install scapy
    • Recommended, Scapy and iPython:
      • $ pip install --pre scapy[basic]
    • Complete, Scapy & all its main dependencies:
      • $ pip install --pre scapy[complete]

    Install optional dependencies

    Scapy requires certain dependencies for some special features, such as for plotting, 2D & 3D graphics, WEP decryption, PKI operations and TLS decryption, fingerprinting and VOIP. Most of these software are installable via pip. Scapy's official documentation presents them along with some examples that test whether the installation was successful.

    Configure libpcap integration

    Scapy's official documentation states that it works natively since the recent versions but it's possible to configure it to use libpcap, which may be installed using either Homebrew or MacPorts. Both installation methods work fine, yet Homebrew is used to run unit tests with Travis CI. Note that Libpcap might already be installed, for example if tcpdump is installed, such as in the case of OSX.

    Install using Homebrew

    $ brew update  # update Homebrew
    $ brew install libpcap  # install libpcap
    

    Enable it in Scapy via from scapy.config import conf; conf.use_pcap = True.

    Install using MacPorts

    $ sudo port -d selfupdate  # update MacPorts
    $ sudo port install libpcap  # install libpcap
    

    Enable it in Scapy via from scapy.config import conf; conf.use_pcap = True.


    EDIT (27.05.15)

    This answer states that all mentioned issues were fixed, and provides a much simpler installation method. However, its comments suggest that although it seems to work on OS X 10.10 Yosemite and OS X 10.11 El Capitan, it might fail for certain other versions.

    $ brew install libdnet --with-python
    $ pip install pcapy
    $ pip install scapy
    

    If Homebrew's site-packages is not in Python's sys.path variable, the following should be executed (see this for more information), with the actual username replacing the placeholder :

    $ mkdir -p /Users//Library/Python/2.7/lib/python/site-packages
    $ echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users//Library/Python/2.7/lib/python/site-packages/homebrew.pth
    

    The original answer

    You have not completed the installation of libdnet and its Python wrapper, as stated in Scapy's installation guide:

    $ wget https://github.com/dugsong/libdnet/archive/libdnet-1.12.tar.gz
    $ tar xfz libdnet-1.12.tgz
    $ ./configure
    $ make
    $ sudo make install
    $ cd python
    $ python2.5 setup.py install
    

    If your system is 64 bit, use these compilation commands instead:

    $ CFLAGS='-arch i386 -arch x86_64' ./configure
    $ archargs='-arch i386 -arch x86_64' make
    

    Moreover, please verify that you've installed the correct version, i.e. 1.12 rather than 1.11.

    If that fails as well, try installing via MacPorts and use its dnet.so file, as described here:

    $ port selfupdate
    $ port upgrade outdated
    $ port install py27-libdnet
    $ port install libdnet 
    $ cp /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dnet.so /Library/Python/2.7/site-packages
    

    That link also recommends changing some code in /Library/Python/2.7/site-packages/scapy/arch/unix.py (fix OSError: Device not configured).

    Change line 34 from:

    f=os.popen("netstat -rn") # -f inet
    

    to:

    f=os.popen("netstat -rn | grep -v vboxnet") # -f inet
    

    as follows:

    def read_routes():
        if scapy.arch.SOLARIS:
    #       f=os.popen("netstat -rvn") # -f inet
            f=os.popen("netstat -rn | grep -v vboxnet") # -f inet
    

    If you still get the error OSError: Device not configured, then try performing similar changes to the other branches of the if clause (specifically, to its else branch), as described in this answer.

提交回复
热议问题