Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scapy In A Script

Tags:

python

scapy

I have used scapy as a session in python, but I want to use it in a script. Why so? I want to be able to use sys.argv to specify an IP address to use as well as use other modules. How can this be accomplished?

like image 214
James Parsons Avatar asked Apr 24 '14 12:04

James Parsons


1 Answers

You just need to import it, as any other Python module.

from scapy.layers.inet import IP, ICMP
from scapy.sendrecv import sr
import sys
sr(IP(dst=sys.argv[1])/ICMP())

Or if you want to import everything at once:

import scapy.all as scapy
import sys
scapy.sr(scapy.IP(dst=sys.argv[1])/scapy.ICMP())
[...]

Or if you want to code exactly as in the Scapy console:

from scapy.all import *
import sys
sr(IP(dst=sys.argv[1])/ICMP())
like image 198
Pierre Avatar answered Nov 14 '22 22:11

Pierre