Building a scapy.exe file for easy deployment on Windows

Problem

You want to use Scapy on several Windows systems, but don't want to install Python and all the needed third-party libraries on every system.

Solution

Use PyInstaller to create a stand-alone scapy.exe executable. Here's how:

1. Install Scapy-win on a development machine as described in the Windows installation guide

2. Download PyInstaller and extract the zip archive to a temporary directory

http://pyinstaller.hpcf.upr.edu/source/1.3/pyinstaller_1.3.zip

3. Open a command prompt there and let PyInstaller find out your configuration

C:\pyinstaller-1.3>python Configure.py

I: computing EXE_dependencies
I: Finding TCL/TK...
I: found TCL/TK version 8.4
I: testing for Zlib...
I: ... Zlib available
I: Testing for ability to set icons, version resources...
I: ... resource update available
I: Testing for Unicode support...
I: ... Unicode available
I: testing for UPX...
I: ...UPX unavailable
I: computing PYZ dependencies...

4. Create a PyInstaller spec-file for Scapy-win

C:\pyinstaller-1.3>python Makespec.py -F c:\scapy-win\scapy.py

wrote C:\pyinstaller-1.3\scapy\scapy.spec
now run Build.py to build the executable

The given path should point to your Scapy-win scapy.py file. In my example, it is at c:\scapy-win\scapy.py.

5. Build the executable using the spec-file:

C:\pyinstaller-1.3>python Build.py scapy\scapy.spec

checking Analysis
building Analysis because out0.toc non existent
running Analysis out0.toc
Analyzing: support\_mountzlib.py
Analyzing: support\useUnicode.py
Analyzing: c:\scapy-win\scapy.py
c:\scapy-win\scapy.py:3520: Warning: 'with' will become a reserved keyword in Python 2.6
c:\scapy-win\scapy.py:3522: Warning: 'with' will become a reserved keyword in Python 2.6
Warnings written to scapy\warnscapy.txt
checking PYZ
rebuilding out1.toc because out1.pyz is missing
building PYZ out1.toc
scapy\buildscapy\out1.pyz/Gnuplot.demo:50: Warning: 'with' will become a reserved keyword in Python 2.6
scapy\buildscapy\out1.pyz/Gnuplot.PlotItems:88: Warning: 'with' will become a reserved keyword in Python 2.6
scapy\buildscapy\out1.pyz/Gnuplot.PlotItems:89: Warning: 'with' will become a reserved keyword in Python 2.6
checking PKG
rebuilding out3.toc because out3.pkg is missing
building PKG out3.pkg
checking ELFEXE
rebuilding out2.toc because scapy.exe missing
building ELFEXE out2.toc

Those 'with will become a reserved keyword' warnings come from the GnuPlot library and can be safely ignored.

6. You'll find the scapy.exe executable in the scapy subdirectory of PyInstaller

C:\pyinstaller-1.3>cd scapy
C:\pyinstaller-1.3\scapy>dir
[...]
22.12.2007  11:53    <DIR>          buildscapy
22.12.2007  11:53         4.959.466 scapy.exe
22.12.2007  11:51               423 scapy.spec
22.12.2007  11:53             9.014 warnscapy.txt
[...]

7. Install WinPcap on your target system

This is the only dependency that you'll still need besides scapy.exe. (I prefer to install Wireshark, which includes a WinPcap installer.)

8. Copy scapy.exe to your target system and run it from the console.

You will get some startup warnings, but most of the features should work.

C:\temp\scapy>scapy.exe
msvcr71.dll could not be extracted!
IPHLPAPI.DLL could not be extracted!
<string>:3520: Warning: 'with' will become a reserved keyword in Python 2.6
<string>:3522: Warning: 'with' will become a reserved keyword in Python 2.6
INFO: Can't import PyX. Won't be able to use psdump() or pdfdump()
Welcome to Scapy (1.2.0.1-win)
>>>

Discussion

As said before, WinPcap needs to be installed on the target system, before scapy.exe can be used.

This stand-alone executable might be a convenient way to show Scapy to your friends.

You can further compress the executable with UPX: Add upx.exe to your PATH and tell Makespec.py to use it. Step 3 changes to the following.

C:\pyinstaller-1.3>python Makespec.py -F --upx c:\scapy-win\scapy.py

Caveats

You can only work interactively. Developing scripts with something like from scapy import * will not work, of course.

This hasn't been tested very much. There will be bugs and it might not even work. Some known issues:

  • help() doesn't work
  • psdump() and pdfdump() don't work

See also

http://pyinstaller.python-hosting.com/

Credits

First version of this recipe by Dirk Loss (2007-12-22).