Home > Uncategorized > [An attempt to] Build scapy with python 2.7 on Windows 7

[An attempt to] Build scapy with python 2.7 on Windows 7

I was never able to get libdnet to compile, with the following errors:
C:\MinGW\bin\gcc.exe -mdll -O -Wall -I../include -I../../WPdpack/Include -IC:\Python27\include -IC:\Python27\PC -c ./dnet.c -o build\temp.win-amd64-2.7\Release\.\dnet.o
In file included from ../include/dnet.h:12:0,
                 from ./dnet.c:22:
../include/dnet/os.h:26:17: error: conflicting types for 'ssize_t'
   typedef long  ssize_t;
In file included from c:\mingw\include\io.h:33:0,
                 from C:\Python27\include/pyconfig.h:68,
                 from C:\Python27\include/Python.h:8,
                 from ./dnet.c:4:
c:\mingw\include\sys\types.h:136:18: note: previous declaration of 'ssize_t' was here
 typedef _ssize_t ssize_t;
./dnet.c:2729:29: error: lvalue required as left operand of assignment
   ((PyObject*)__pyx_v_next) = Py_None; Py_INCREF(((PyObject*)__pyx_v_next));
./dnet.c:2741:32: error: lvalue required as left operand of assignment
     ((PyObject *)__pyx_v_next) = __pyx_3;

Instead, I just installed python 2.6.3, and run python 2.7.6 64-bit for other things.

Here is the post for prosperity.

You must use python 2.7 32-bit. If you do not use python 32-bit, you must modify the libdnet code, and that won’t be pretty.

1) Install python 2.7.6 32-bit & make sure that c:\python27 and c:\python27\libs are present in the PATH:

2) Install setuptools: https://bitbucket.org/pypa/setuptools/raw/0.8/ez_setup.py

3) Install pip: https://raw.github.com/pypa/pip/master/contrib/get-pip.py

4) Install pywin32: http://www.lfd.uci.edu/~gohlke/pythonlibs/shgi5ox7/pywin32-218.4.win32-py2.7.exe

5) Install WinPcap (may as well install wireshark): http://www.wireshark.org/download.html

6) Install pypcap: http://winappdbg.sourceforge.net/blog/pcapy-0.10.5.win32-py2.7-winpcap4.1.2.exe

7) Install pyreadline: http://www.lfd.uci.edu/~gohlke/pythonlibs/shgi5ox7/pyreadline-2.0.win32-py2.7.exe

8) Install libdnet for python 2.7.x (a horrible process):

a) install mingw and msys (install “mingw32-gcc-g++” and “msys-base”): https://downloads.sourceforge.net/project/mingw/Installer/mingw-get-setup.exe
b) verify that c:\mingw\bin is available in the %PATH% (try starting a new cmd.exe)
c) setup fstab:

copy c:\MinGW\msys\1.0\etc\fstab.sample c:\MinGW\msys\1.0\etc\fstab
echo C:\MinGW\ /usr/local >> c:\MinGW\msys\1.0\etc\fstab

d) setup python root environment(or your virtualenv!):

copy /y c:\Python27\Lib\distutils\distutils.cfg c:\Python27\Lib\distutils\distutils.cfg.bak
echo [build] > c:\Python27\Lib\distutils\distutils.cfg
echo compiler=mingw32 >> c:\Python27\Lib\distutils\distutils.cfg

e) Start mingwin:


f) install some packages:

#in msys.bat/mingw:
mingw-get install gcc g++ mingw32-make msys-patch msys-wget

g) download libdnet:

#in msys.bat/mingw:
wget http://prdownloads.sourceforge.net/libdnet/libdnet-1.11.tar.gz?download
#wget --no-check-certificate https://libdnet.googlecode.com/files/libdnet-1.12.tgz

h) decompress:

#in msys.bat/mingw:
tar zxvf libdnet-1.11.tar.gz

i) Configure the Build for python 2.7.x

#in msys.bat/mingw:
cd libdnet-1.11

j) Build libdnet:

#in cmd.exe
cd c:\MinGW\msys\1.0\home\%username%\libdnet-1.11\python
C:\Python27\python.exe setup.py install

9) Install scapy: http://hg.secdev.org/scapy/archive/tip.zip


  1. Andre
    February 28, 2015 at 2:16 pm

    Wow! Great post. I will try to follow your instructions. Could you just clarify the last point (#9). Is it as simple as unziping the file? If so, into which folder should it be unzipped?

    • February 28, 2015 at 4:43 pm

      Thanks. To be honest, I don’t recall, but I assume yes. :D

  2. Andre
    March 1, 2015 at 12:10 am

    Everything was going well. I got almost to the end. When I tried to build the libdnet (step 8-j) the C:\Python27\python.exe setup.py install run with many warnings (unused labes, unused variables, unused functions) and then I got:
    error: command ‘gcc’ failed with exit status 1
    I checked that gcc is in c:\MinGW\bin, and that directory is included in PATH variable. Would you have any suggestion?

    • March 2, 2015 at 9:06 am

      Yes. This sounds to be the same exact problem I ran into.

  3. June 2, 2015 at 9:34 am

    Hi all,
    please check the following discussion https://github.com/boundary/libdnet/issues/3
    It contains different instructions and methods for building scapy on win32 with dnet.


  4. Michael beaver
    November 9, 2015 at 5:50 pm

    Does anyone have procedure tobuild scapy on Android platform?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: