Skip to content

Instantly share code, notes, and snippets.

@Rgghgh
Created September 17, 2022 18:22
Show Gist options
  • Save Rgghgh/03e060579bdc910d14acce81d177b4de to your computer and use it in GitHub Desktop.
Save Rgghgh/03e060579bdc910d14acce81d177b4de to your computer and use it in GitHub Desktop.
from scapy.all import *
from scapy.utils import PcapWriter
packets = rdpcap('cap.pcap')
new_cap = PcapWriter("cap_new.pcap")
# old: new
mapping = {
'203.76.192.10': '1.1.1.1'
}
#replace orinigal address
for p in packets:
if (p[IP].src in mapping):
p[IP].src = mapping[p[IP].src]
if (p[IP].dst in mapping):
p[IP].dst = mapping[p[IP].dst]
new_cap.write(p)
wrpcap("cap_new.pcap", packets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment