Scapy-python-based interactive packet manipulation program & library.

Scapy is a powerful Python-based interactive packet manipulation program and library.
It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, store or read them using pcap files, match requests and replies, and much more. It is designed to allow fast packet prototyping by using default values that work.
It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery (it can replace hping, 85% of nmaparpspoofarp-skarpingtcpdumpwiresharkp0f, etc.). It also performs very well at a lot of other specific tasks that most other tools can't handle, like sending invalid frames, injecting your own 802.11 frames, combining techniques (VLAN hopping+ARP cache poisoning, VoIP decoding on WEP protected channel, ...), etc.
Scapy supports Python 2.7 and Python 3 (3.3 to 3.6). It's intended to be cross platform, and runs on many different platforms (Linux, OSX, *BSD, and Windows).

Hands-on

Interactive shell

Scapy can easily be used as an interactive shell to interact with the network. The following example shows how to send an ICMP Echo Request message to github.com, then display the reply source IP address:
sudo ./run_scapy 
Welcome to Scapy
>>> p = IP(dst="github.com")/ICMP()
>>> r = sr1(p)
Begin emission:
.Finished to send 1 packets.
*
Received 2 packets, got 1 answers, remaining 0 packets
>>> r[IP].src
'192.30.253.113'

Python module

It is straightforward to use Scapy as a regular Python module, for example to check if a TCP port is opened. First, save the following code in a file names send_tcp_syn.py
from scapy.all import *
conf.verb = 0

p = IP(dst="github.com")/TCP()
r = sr1(p)
print(r.summary())
Then, launch the script with:
sudo python send_tcp_syn.py
IP / TCP 192.30.253.113:http > 192.168.46.10:ftp_data SA / Padding

                            Source and download

No comments