Created
January 31, 2020 14:50
-
-
Save origamium/9de6fde5716245e4b879d5cd02d6d397 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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