Skip to content

Instantly share code, notes, and snippets.

@hgn
Created January 24, 2014 09:52
Show Gist options
  • Save hgn/8594729 to your computer and use it in GitHub Desktop.
Save hgn/8594729 to your computer and use it in GitHub Desktop.
captcp-constantly-graph
#!/usr/bin/env python
# remember to edit /etc/sudoers file and grant tcpdump without
# password access to work in a scripting environment. sudo visudo
# username ALL=NOPASSWD:ALL,/sbin/tcpdump,/usr/bin/kill
import os
import signal
import subprocess
import sys
import time
tcpdump_interface = "p3p1"
tcpdump_filter = "port 5001"
tcpdump_cmd = "sudo /sbin/tcpdump -w trace.pcap -i %s %s" % (tcpdump_interface, tcpdump_filter)
def signal_handler(s, frame):
print '\rYou pressed Ctrl+C!'
cmd = "sudo /usr/bin/kill -9 tcpdump"
subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, shell=False)
sys.exit(0)
def msg(string):
sys.stdout.write(string)
signal.signal(signal.SIGINT, signal_handler)
msg("execute: %s\n" % (tcpdump_cmd))
subprocess.Popen(tcpdump_cmd.split(), stdout=subprocess.PIPE, shell=False, preexec_fn=os.setsid)
time.sleep(1)
cmd_cap = "captcp timesequence -o graph-out -f 1.1 -z -w trace.pcap"
cmd_graph = "make"
while True:
subprocess.Popen(cmd_cap.split(), stdout=subprocess.PIPE, shell=False)
cwd = os.getcwd()
os.chdir("graph-out")
subprocess.Popen(cmd_graph.split(), stdout=subprocess.PIPE, shell=True)
os.chdir(cwd)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment