Skip to content

Instantly share code, notes, and snippets.

@dwallraff
Last active September 14, 2016 17:10
Show Gist options
  • Save dwallraff/0100efe2f3004498bfd9b37b8b737ba8 to your computer and use it in GitHub Desktop.
Save dwallraff/0100efe2f3004498bfd9b37b8b737ba8 to your computer and use it in GitHub Desktop.
Use python to tcpump (outputs PCAP)
#!/usr/bin/env python
import sys,socket,struct,time
sys.stdout.write(struct.pack('!IHHIIII',0xa1b2c3d4,2,4,0,0,65535,1))
s=socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(0x3))
while True:
t,p=time.time(),s.recvfrom(65535)
ts=int(t)
tu=int((t-ts)*1000000)
sys.stdout.write(struct.pack('!IIII',ts,tu,len(p[0]),len(p[0]))+p[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment