Skip to content

Instantly share code, notes, and snippets.

@austinhappel
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinhappel/8910564 to your computer and use it in GitHub Desktop.
Save austinhappel/8910564 to your computer and use it in GitHub Desktop.
pipe `ping` command into this and get csv-friendly data for graphing. Usage: `ping -D | ./ping2csv.py > file.csv`. Note: the `-D` might not be supported on your implementation of `ping`.
#!/usr/bin/python
import sys
import datetime
import re
# usage: `ping -D google.com | ./ping2csv.py > file.csv`
try:
buff = ''
while True:
buff += sys.stdin.read(1)
if len(buff) == 0:
exit(1)
if buff.endswith('\n'):
temp = buff[:-1]
matches = re.search('\[([0-9\.]+)\].*time\=([0-9\.]+)', temp)
if hasattr(matches, 'group'):
timestamp = datetime.datetime.fromtimestamp(float(matches.group(1)))
ping = matches.group(2)
print("%s,%s" % (timestamp, ping))
buff = ''
except KeyboardInterrupt:
sys.stdout.flush()
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment