Added function to ping a host
This commit is contained in:
10
status.py
10
status.py
@@ -1,4 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
from pythonping import ping
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def parseArguments():
|
def parseArguments():
|
||||||
@@ -23,8 +24,15 @@ def parseArguments():
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit()
|
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__':
|
if __name__ == '__main__':
|
||||||
args = parseArguments()
|
args = parseArguments()
|
||||||
print(args)
|
print(check_ping(args))
|
||||||
|
|||||||
Reference in New Issue
Block a user