How to use the dnsdiag.myResolver function in dnsdiag

To help you get started, we’ve selected a few dnsdiag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github farrokhi / dnsdiag / dnsdiag.py View on Github external
except OSError:
            print('Error: cannot resolve hostname:', dnsserver)
            sys.exit(1)

    # Lookup from master parent
    res = myResolver(nameservers=[default_parent], port=dst_port, af=address_family, use_tcp=use_tcp)
    printHeader("Domain NS Records (from parent: %s)" % default_parent)
    answers = res.lookupNS(hostname)
    for a in answers:
        A = res.lookupA(a.target)
        AAAA = res.lookupAAAA(a.target)
        print("%-25s\t%s\t%s" % (a.target, '\t'.join(A), '\t'.join(AAAA)))

    # Lookup from your DNS server
    yourdns = str(a.target)
    res = myResolver(nameservers=[yourdns], port=dst_port, af=address_family, use_tcp=use_tcp)
    printHeader("Domain NS Records (from your DNS: %s)" % a.target)
    answers = res.lookupNS(hostname)
    for a in answers:
        A = res.lookupA(a.target)
        AAAA = res.lookupAAAA(a.target)
        print("%-25s\t%s\t%s" % (a.target, '\t'.join(A), '\t'.join(AAAA)))
github farrokhi / dnsdiag / dnsdiag.py View on Github external
if not validHostname(hostname):
        print("Invalid hostname:", hostname)
        exit(1)

    # check if a valid DNS Server is provided
    try:
        ipaddress.ip_address(dnsserver)
    except ValueError:  # so it is not a valid IPv4 or IPv6 address, so try to resolve host name
        try:
            dnsserver = socket.getaddrinfo(dnsserver, port=None, family=address_family)[1][4][0]
        except OSError:
            print('Error: cannot resolve hostname:', dnsserver)
            sys.exit(1)

    # Lookup from master parent
    res = myResolver(nameservers=[default_parent], port=dst_port, af=address_family, use_tcp=use_tcp)
    printHeader("Domain NS Records (from parent: %s)" % default_parent)
    answers = res.lookupNS(hostname)
    for a in answers:
        A = res.lookupA(a.target)
        AAAA = res.lookupAAAA(a.target)
        print("%-25s\t%s\t%s" % (a.target, '\t'.join(A), '\t'.join(AAAA)))

    # Lookup from your DNS server
    yourdns = str(a.target)
    res = myResolver(nameservers=[yourdns], port=dst_port, af=address_family, use_tcp=use_tcp)
    printHeader("Domain NS Records (from your DNS: %s)" % a.target)
    answers = res.lookupNS(hostname)
    for a in answers:
        A = res.lookupA(a.target)
        AAAA = res.lookupAAAA(a.target)
        print("%-25s\t%s\t%s" % (a.target, '\t'.join(A), '\t'.join(AAAA)))
github farrokhi / dnsdiag / dnsdiag.py View on Github external
def __init__(self, nameservers=None, port=53, af=socket.AF_INET, use_tcp=False):
        super(myResolver, self).__init__()
        self.use_tcp = use_tcp
        self.port = port
        self.default_af = af
        self.port = port
        self.retry_servfail = 0
        resolved_nameservers = []
        for n in nameservers:
            try:
                ipaddress.ip_address(n)
            except ValueError:  # so it is not a valid IPv4 or IPv6 address, so try to resolve host name
                try:
                    r = socket.getaddrinfo(n, port=None, family=self.default_af)[1][4][0]
                except OSError:
                    print('Error: cannot resolve hostname:', n)
                    # sys.exit(1)
                    return  # todo: to be handled gracefully

dnsdiag

DNS Measurement, Troubleshooting and Security Auditing Toolset (ping, traceroute)

BSD-2-Clause
Latest version published 2 months ago

Package Health Score

82 / 100
Full package analysis

Popular dnsdiag functions

Similar packages