martin carpenter


most popular
2012/05/05, updated 2012/12/15
ubuntu unity lens for vim

forging ip packets with scapy


tags: python scapy

github home
repository URLs

If you don't have python's scapy module in your toolbox then you should really add it. The API makes me wince slightly (two-letter method names, postfixed by integers (sr1, sr2)) but it provides some really powerful functionality over all layers of the network stack.

Sometimes I need to poke at the network with forged packets. I (finally) wrote to help me do that. telnet(1) works fine in the majority of cases for simple TCP connection testing... but otherwise it doesn't:

If you need to do more advanced packet forgery then of course scapy can help you do that too. Meanwhile you can hit ipforge from a shell script to do the simple stuff:

while true ; do -f S -p tcp
  sleep 1

Or from native python:

from ipforge import ipforge
from time import sleep
while True:
    ipforge(src='', dst='', dport=666, flags='S')