This entry is part 2 of 11 in the series Building Network Tools with Scapy

Installing Python

Scapy was originally written for python2, but thanks to this wonderful project, you can now use scapy with python3.6! I will prefer python3.6 in examples but will also include notes about big differences between each python version and scapy if they exist.

If you’re using a Mac or running some version of *nix you probably already have python 2 (and maybe even python 3) installed. To check, open a terminal and type python3 or python. You should see something like this:

If you are running Windows or for some other reason do not have Python installed already, go to the Python download page and grab the installer for your platform.

Installing Scapy3k (for python 3)

You can install Scapy3k and its dependencies using pip3 and Homebrew:

Once Scapy3k is installed, you should be able to run it from the terminal, just like we did with Python, and get something that looks like this:

You’ll also have to install libdnet, check out their page for download/install info. If you’re on a different platform and have trouble installing Scapy3k, I recommend going to Stack Overflow for help.

Installing Scapy (for python 2)

There are multiple ways to install Scapy depending on your platform. Check out the Scapy installation guides to find instructions and installer packages relevant to your platform. Once Scapy is installed, you should be able to run it from the terminal, just like we did with Python, and get something that looks like this:

The easiest way I’ve found to install Scapy on the Mac is with MacPorts. If you have xcode and macports already installed, all you need to do is run:

and macports will install all the necessary dependencies.

If you’re on a different platform and have trouble installing Scapy3k, I recommend going to the project page for help.

Scapy and Network Interfaces

If you have multiple network interfaces on your computer, you might have to double check which one Scapy will use by default. Run scapy from the terminal and run the conf command. See what interface Scapy will use by default by looking at the iface value:

Python 3:

Python 2:

 

Scapy on my computer is defaulted to my en0 (Wifi) interface

If the default interface is not the one you will use, you can change the value like this:

 

Instead of en3, use the interface you want to be your default

If you are constantly switching back and forth between interfaces, you can specify the interface to use when you run scapy commands. Here are some Scapy functions and how you might use the iface argument. You’ll learn more about these functions and other arguments soon.

 

Root Permissions

For some of the Scapy functions dealing with sending traffic, you will need to be able to run Scapy as root. For example, on a Mac/Linux computer you can run interactive mode with root permissions by running sudo scapy from the CLI. Also, you can run the Python scripts with Scapy send functions as sudo like this:

If you ever receive a Python error about not having the correct permissions or something not be allowed, try running Scapy with root permissions.

 

Series Navigation<< Scapy p.01 – Scapy Introduction and OverviewScapy p.03 – Scapy Interactive Mode >>

This article has 3 comments

Leave a Reply

Your email address will not be published. Required fields are marked *