Skip to content

Instantly share code, notes, and snippets.

@origamium
Created January 31, 2020 14:50
Show Gist options
  • Save origamium/9de6fde5716245e4b879d5cd02d6d397 to your computer and use it in GitHub Desktop.
Save origamium/9de6fde5716245e4b879d5cd02d6d397 to your computer and use it in GitHub Desktop.
import sys, subprocess, re
args = sys.argv
if len(args) == 0:
sys.exit(-1)
dst = args[1]
t = 1
while True:
proc = subprocess.run(["ping", dst, "-m", str(t), "-v", "-t", "1"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = proc.stdout.decode("utf8")
isError = result.find("(Request timeout)|(Unknown host)")
if isError != -1:
sys.exit(-1)
isExceeded = result.find("Time to live exceeded")
if isExceeded == -1:
break
match = re.search("(bytes from )(.*)(:)", result, re.MULTILINE)
print(str(t) + " \t" + match.group()[11:-1])
t += 1
print(str(t) + " \t" + dst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment