Added function to ping a host

This commit is contained in:
2024-04-07 14:20:51 +02:00
parent 48f773f374
commit 439a7d545e

View File

@@ -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))