this function receives a DNS name.I test if I can "ping" each site and return whether true if UP or false if DOWN.
But the problem is that some sites display return false when they are true. (e.g.: google.com)
Do you have any other idea to improve this function to be even more efficient?
Thank you.
def ping_ip(dns_name):
try:
output = subprocess.check_output("ping -{} 1 {}".format('n' if platform.system().lower(
) == "windows" else 'c', dns_name), shell=True, universal_newlines=True)
if 'unreachable' in output:
return False
else:
return True
except Exception:
return False