Skip to content

Instantly share code, notes, and snippets.

@jlongman
Created May 11, 2015 21:40
Show Gist options
  • Save jlongman/24deb2f8aaef1d2afa30 to your computer and use it in GitHub Desktop.
Save jlongman/24deb2f8aaef1d2afa30 to your computer and use it in GitHub Desktop.
dpkt GRE stripping
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Extracts IP content from GRE and writes to arg[1].out
# Drops non GRE
# requires dpkt gre patch
import dpkt
import sys
fin = open(sys.argv[1])
fout = open(sys.argv[1] + ".out", "w")
pcap = dpkt.pcap.Reader(fin)
pcapout = dpkt.pcap.Writer(fout)
frame_counter = 0
for ts, buf in pcap:
eth = dpkt.ethernet.Ethernet(buf)
ip = eth.data
if ip.p == 47:
payload = ip.data.data
inner_ip = payload.data
eth.data = inner_ip
pcapout.writepkt(eth)
fin.close()
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment