Reputation: 608
This is my script to generate http traffic
from scapy.all import *
from random import randint
import time
from threading import *
# Generate packet
pkts = IP(src="10.0.0.1",dst="10.0.0.2")/TCP()/"GET /HTTP/1.0\r\n\r\n"/Raw(RandString(size=120))
#print pkts
pkts[TCP].flags = "S"
pktList = []
for pktNum in range(0,20):
pktList.extend(pkts)
pktList[pktNum][TCP].dport = randint(1,65535) # Pkt has Ran PortNo.
print pktList[pktNum].summary()
print len(pktList[pktNum])
# Send the list of packets
start_time=time.time()
send(pktList)
print time.time() - start_time,"seconds"
#print start_time, "secs"
pktList[0].show()
Now the issue is I am not been able to send the traffic at a customize Byte/sec Rate. How Would I be able to send according to my own needs ?
Upvotes: 1
Views: 2679
Reputation: 3159
Please, refer to the documentation on scapy, specifically page 35. You may specify the rate by varying the inter
parameter in the send
command.
For example to achieve the rate of 100 packets per second you may write:
send(pktList, inter = 0.01)
To have more control you may use sendpfast command from scapy where you can define the bitrate (mbps argument):
sendpfast(pkt, pps=N, mbps=N, loop=0, iface=N)
Upvotes: 3