I am trying to send a previously recorded traffic (captured in pcap format) with scapy. Currently I am stuck at striping original Ether layer. The traffic was captured on another host and I basically need to change both IP and Ether layer src and dst. I managed to replace IP layer and recalculate checksums, but Ether layer gives me trouble.
Anyone has experience resending packets from capture file with applied changes to IP and Ether layer(src and dst)? Also, the capture is rather big couple of Gb, how about scapy performance with such amounts of traffic?
check this example
from scapy.all import *
from scapy.utils import rdpcap
pkts=rdpcap("FileName.pcap") # could be used like this rdpcap("filename",500) fetches first 500 pkts
for pkt in pkts:
pkt[Ether].src= new_src_mac # i.e new_src_mac="00:11:22:33:44:55"
pkt[Ether].dst= new_dst_mac
pkt[IP].src= new_src_ip # i.e new_src_ip="255.255.255.255"
pkt[IP].dst= new_dst_ip
sendp(pkt) #sending packet at layer 2
comments:
sniff(offline="filename")
to read packets and you may use prn parameter like this sniff(offline="filename",prn=My_Function)
in this case My_Functions will be applied to every pkt sniffedip="1.1.1.1"
and so on as illustrated above.