diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:17:45 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:17:45 -0700 |
| commit | a33d49ac4d1ce554c72770927957a089b4023bf1 (patch) | |
| tree | 17ea036b5a0e8b488dc236f0ce48a275ecd80ef8 /python/personal/ping an address.py | |
Diffstat (limited to 'python/personal/ping an address.py')
| -rw-r--r-- | python/personal/ping an address.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/python/personal/ping an address.py b/python/personal/ping an address.py new file mode 100644 index 0000000..6ae13c1 --- /dev/null +++ b/python/personal/ping an address.py @@ -0,0 +1,26 @@ +import subprocess +import platform + +hostname = "something" + +# ping parameters +# -c (count): number of packets to send +# -W (timeout): time to wait for a response, in seconds +ping_count = 5 +ping_timeout = 1 + +# determine the system type (Windows or Unix-based) +system = platform.system().lower() +if system == "windows": + ping_args = ["ping", "-n", str(ping_count), "-w", str(ping_timeout * 1000), hostname] +else: + ping_args = ["ping", "-c", str(ping_count), "-W", str(ping_timeout), hostname] + +# run the ping command +result = subprocess.run(ping_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + +# check if the ping was successful +if result.returncode == 0: + print(f"{hostname} is reachable.") +else: + print(f"{hostname} is unreachable.") |
