ServerDowntimeNotifier/ServerPingService.py

19 lines
336 B
Python

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:
"""
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