Added function to ping a host
This commit is contained in:
10
status.py
10
status.py
@@ -1,4 +1,5 @@
|
||||
import argparse
|
||||
from pythonping import ping
|
||||
import sys
|
||||
|
||||
def parseArguments():
|
||||
@@ -23,8 +24,15 @@ def parseArguments():
|
||||
parser.print_help()
|
||||
exit()
|
||||
|
||||
def check_ping(host):
|
||||
try:
|
||||
response = ping(host, count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
||||
return True if response.success() else False
|
||||
except Exception as e:
|
||||
print(f"Error making ping to {host}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parseArguments()
|
||||
print(args)
|
||||
print(check_ping(args))
|
||||
|
||||
Reference in New Issue
Block a user