Skip to content

Instantly share code, notes, and snippets.

@moshohayeb
Last active March 18, 2020 10:28
Show Gist options
  • Save moshohayeb/0c8602e9861fce5a1770def4e8f685a1 to your computer and use it in GitHub Desktop.
Save moshohayeb/0c8602e9861fce5a1770def4e8f685a1 to your computer and use it in GitHub Desktop.
Recalculate pcap ipv4 header checksum
#!/usr/bin/env python3
import sys
from scapy.all import *
def fix(infile, outfile):
i = 0
# packets = rdpcap(infile)
fp = PcapWriter(outfile, append=True, sync=True)
for p in PcapReader(infile):
i += 1
if (i % 100 == 0):
print(i)
if p.haslayer(IP):
del (p.chksum)
npacket = p.__class__(bytes(p))
fp.write(npacket)
if __name__ == '__main__':
if len(sys.argv) != 3:
print("Bad number of args, put infile and outfile")
sys.exit(1)
in_file=sys.argv[1]
out_file=sys.argv[2]
fix(in_file, out_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment