import re
import subprocess
import sys
from tabulate import tabulate
def main():
address = sys.argv[1]
pingthis = ['ping', '-c', '1', address]
r = (
subprocess
.run(
pingthis,
stdout=subprocess.PIPE,
check=True,
)
.stdout
.decode('utf-8')
)
table = tabulate(
[[address, (re.search(r'time=(d+)', r).group(1))]],
headers=["IP", "TimeToPing (ms)"],
tablefmt="simple",
)
print(table)
if __name__ == "__main__":
main()