Traceroute system call in python
#!/usr/bin/env python
 
from subprocess import Popen, PIPE
import sys
 
def tracer(host=None):
	p = Popen(['traceroute', host], stdout=PIPE)
 
	while True:
		try:
			line = p.stdout.readline()
			if not line:
				break
			print (line.rstrip())
		except:
			break
 
def main(argv=None):
	tracer(sys.argv[1])
 
if __name__ == "__main__":
	sys.exit(main())
Categories: Python Tags: , , ,
%d bloggers like this: