Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send packets in python?

Tags:

python

scapy

I tried this piece of code for sending packet using scapy in python

data= "University of texas at San Antonio"
a=IP(dst="129.132.2.21")/TCP()/Raw(load=data)
sendp(a)

But I'm getting error in third line "sendp(a)" saying

Traceback (most recent call last):
   File "<pyshell#7>", line 1, in <module>
     sendp(a)
   File "C:\Python25\lib\site-packages\scapy\sendrecv.py", line 259, in sendp
     __gen_send(conf.L2socket(iface=iface, *args, **kargs), x, inter=inter, loop=loop, 
   count=count, verbose=verbose, realtime=realtime)
   File "C:\Python25\lib\site-packages\scapy\arch\pcapdnet.py", line 313, in __init__
     self.outs = dnet.eth(iface)
   File "dnet.pyx", line 112, in dnet.eth.__init__
   OSError: No such file or directory

Please let me know where am I wrong.

like image 621
user3099822 Avatar asked Oct 03 '22 04:10

user3099822


1 Answers

You are using sendp() directly with IP packets, which is wrong.

Use either sendp(Ether()/IP()/...) or send(IP()/...).

By the way, you don't need to add Raw(load=...), as Scapy treats str as Raw.

So try this:

data = "University of texas at San Antonio"
a = IP(dst="129.132.2.21")/TCP()/data
send(a)
like image 116
Pierre Avatar answered Oct 17 '22 01:10

Pierre