0

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

Malikari
  • 1
  • 2

2 Answers2

2

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...

ampw
  • 175
  • 10
  • In El Capitan and Sierra, due to [System Integrity Protection](https://support.apple.com/en-us/HT204899), even when using `sudo`, one can't create links in `/usr/lib`. Instead, use `/usr/local/lib`. Also, the file extensions on Mac OS X (MacOS) are `.dylib`, vs `.so`. Additionally, if using MacPorts, the files will live in `/opt/local/lib`. Refer to this [SO article](http://stackoverflow.com/questions/36730549/cannot-create-a-symlink-inside-of-usr-bin-even-as-sudo) for additional details. – tdfunk Apr 06 '17 at 20:31
0

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

Eriks Dobelis
  • 913
  • 7
  • 16
  • I'm not sure how to get ctypes to find my dnet library - it seems libdnet only wants to install to Python2 paths. How do I disable dnet for scapy? – Malikari Jun 29 '15 at 21:14
  • From python doc: On OS X, find_library() tries several predefined naming schemes and paths to locate the library... Unfortunately I don't have OS X to tell you how to install dnet. Can you find libdnet.so on your hard drive? And copy it to some good location /usr/local/lib or /usr/lib? After you get OSError, can you still use scapy functionality (except for sending/receiving packets)? – Eriks Dobelis Jun 30 '15 at 06:31
  • 1
    I checked on OS X machine - you just have to install libdnet with Homebrew http://brew.sh (brew install libdnet). If it succeeds, scapy works fine. – Eriks Dobelis Jun 30 '15 at 13:51
  • It seems that it is currently at /Library/Python/2.7/site-packages/dnet.so. I've tried copying it to the 3.4 library location, as well as /usr/local/lib, and ctypes still cannot find it. I cannot use any scapy functionality after the OSError. – Malikari Jun 30 '15 at 14:08
  • brew installs successfully, and symlinks in usr/local, but ctypes is still not finding it in python3. – Malikari Jun 30 '15 at 14:13
  • Something is just wrong with your python3 or library configuration. Try uninstalling python3, libnet, python 2.7 packages with libdnet, then reinstalling (python3 as per python.org instructions, libdnet with brew). If library is in expected path under /usr/local/lib then python3 should be able to find it. – Eriks Dobelis Jun 30 '15 at 20:12