ServerDowntimeNotifier/ServerPingService.py

19 lines
336 B
Python
Raw Normal View History

2021-03-10 21:07:52 +00:00
import ping3
def ping(host: str) -> int:
"""
Pings the given host and returns the time the ping took ins ms or -1 if the ping was not successful
:param host:
:return:
"""
2021-03-20 18:37:17 +00:00
NUMBER_OF_ATTEMPTS = 5
for iteration in range(NUMBER_OF_ATTEMPTS):
res = ping3.ping(dest_addr=host, unit='ms')
if res:
return int(res)
return -1