-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.py
More file actions
30 lines (24 loc) · 777 Bytes
/
Copy pathping.py
File metadata and controls
30 lines (24 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import subprocess
import platform
def ping_ip(ip_address):
"""
Pings a given IP address once and returns whether the ping was successful.
Args:
ip_address (str): The IP address to ping.
Returns:
bool: True if the ping succeeds, False otherwise.
"""
try:
if platform.system().lower() == "windows":
parameters = ['-n', '1', '-w', '1000']
else:
parameters = ['-c', '1', '-W', '1']
response = subprocess.run(
['ping'] + parameters + [ip_address],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
return response.returncode == 0
except Exception as e:
print(f"Error pinging: {e}")
return False