0

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
bendour
  • 61
  • 5
  • See [Pinging servers in Python](https://stackoverflow.com/questions/2953462/pinging-servers-in-python), [Ping a site in Python?](https://stackoverflow.com/questions/316866/ping-a-site-in-python), and the links therein. – Nikolaos Chatzis Nov 01 '21 at 20:29

0 Answers0