Python 100 project #27: DNS resolve checker

DNS highjack is a classic direction of the attack. It re-write the routers dns, and as a result all the systems(mobile, PC, basically any) are affected. Time to time, I see this news, so I created a simple dns checker to confirm if specified FQDN(full qualified domain) is resolved both system dns(presuming the system dns is distributed from the router via dhcp) and external dns(this time and


Output Example:

$ python3 ''
The same result is returned for
$ python3 ''
!!!There seems problem with!!!


Here is the code:

import sys

import dns.resolver

NAMESERVERS = ['', '']

def is_resolved_same(fqdn):

    res = dns.resolver.Resolver()


        sys_resolved_ip = res.query(fqdn)

        ex_resolved_ip = set()
        for ns in NAMESERVERS:
            res.nameservers = [ns]

        for rdata in sys_resolved_ip:
            if rdata not in ex_resolved_ip:
                return False

        return False

    return True

if __name__ == "__main__":

    if len(sys.argv) != 2:
        print(f"Usage: {sys.argv[0]} 'fqdn'")
    if is_resolved_same(sys.argv[1]):
        print(f"The same result is returned for {sys.argv[1]}.")
        print(f"!!!There seems problem with {sys.argv[1]}.!!!")