Last active
January 24, 2024 22:29
-
-
Save gniting/0efb16b8210235aa15dae11c5ef771fe to your computer and use it in GitHub Desktop.
Help ControlD team
This file contains 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 subprocess | |
def run_command(command): | |
return subprocess.run(command, capture_output=True, text=True).stdout | |
def ping_host(host): | |
return run_command(['ping', '-c', '5', host]) | |
def run_mtr(host): | |
return run_command(['mtr', '-4', '-z', '-r', '-c', '5', host]) | |
def format_ping_output(host, output): | |
lines = output.strip().split('\n') | |
stats = "\n".join(lines[-2:]) | |
return f"--- {host} ping statistics ---\n{stats}" | |
hosts = ["1.1.1.1", "dns.adguard-dns.com", "dns.controld.com", "steering.nextdns.io", "dns.google", "dns.quad9.net"] | |
for host in hosts: | |
ping_output = ping_host(host) | |
formatted_ping = format_ping_output(host, ping_output) | |
print(formatted_ping) | |
mtr_output = run_mtr(host) | |
print(mtr_output) | |
print("\n" + "-"*50 + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment