Malikari
Malikari

Reputation: 1

Python3 cannot find libdnet - Scapy port

I am trying to use the Python3 fork of Scapy in my project, but I am having trouble getting it running with all of its dependencies. I am currently running OSX Yosemite. In particular, it seems Python3 cannot find libdnet.so. I have Scapy working in Python2, so libdnet exists on my system - how do I get it working in Python3? Is there a supported version of libdnet for Python3? Error is as follows:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from scapy.all import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/scapy/all.py", line 16, in <module>
from .arch import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/scapy/arch/__init__.py", line 75, in <module>
from .bsd import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/scapy/arch/bsd.py", line 12, in <module>
from .unix import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/scapy/arch/unix.py", line 21, in <module>
from .pcapdnet import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/scapy/arch/pcapdnet.py", line 22, in <module>
from .cdnet import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/scapy/arch/cdnet.py", line 17, in <module>
raise OSError("Cannot find libdnet.so")
OSError: Cannot find libdnet.so

Thanks

Upvotes: 0

Views: 2267

Answers (2)

ampw
ampw

Reputation: 303

I ran in to this same issue. I installed libdnet and libpcap with homebrew (e.g., in /usr/local/lib), but ctypes could never find them using find_library(). This is not a solution, but a hack to get scapy to import. I modified the following two files in my scapy installation to specify the full path to the libraries:

  • I changed find_library('dnet') in scapy/arch/cdnet.py to find_library('/usr/local/lib/libdnet')
  • I changed find_library('pcap') in scapy/arch/winpcapy.py to find_library('/usr/local/lib/libpcap')

Another less invasive idea is to just link these two libraries from /usr/local/lib to /usr/lib...

Upvotes: 2

Eriks Dobelis
Eriks Dobelis

Reputation: 913

This is the code fragment that generates the exception.

from ctypes import *
from ctypes.util import find_library
_lib_name = find_library('dnet')
if not _lib_name:
  raise OSError("Cannot find libdnet.so")
_lib=CDLL(_lib_name)

Apparently, python ctypes cannot find dnet library on your computer. Once you can get ctypes find dnet, it should work with scapy.

Also, usage of dnet is not mandatory. Try scapy with dnet disabled. You do not need it for parsing packets. And depending on the system, for some limited sending scapy can use pcap, too.

Please, file an issue on https://github.com/phaethon/scapy

Upvotes: 0

Related Questions