示例#1
0
def revlookup(name):
    "convenience routine for doing a reverse lookup of an address"
    if Base.defaults['server'] == []: Base.DiscoverNameServers()
    a = string.split(name, '.')
    a.reverse()
    b = string.join(a, '.') + '.in-addr.arpa'
    # this will only return one of any records returned.
    return Base.DnsRequest(b, qtype='ptr').req().answers[0]['data']
示例#2
0
def mxlookup(name):
    """
    convenience routine for doing an MX lookup of a name. returns a
    sorted list of (preference, mail exchanger) records
    """
    if Base.defaults['server'] == []: Base.DiscoverNameServers()
    a = Base.DnsRequest(name, qtype='mx').req().answers
    l = map(lambda x: x['data'], a)
    l.sort()
    return l
示例#3
0
def dnslookup(name,qtype):
    "convenience routine to return just answer data for any query type"
    if Base.defaults['server'] == []: Base.DiscoverNameServers()
    result = Base.DnsRequest(name=name, qtype=qtype).req()
    if result.header['status'] != 'NOERROR':
        raise DNSError("dns query status: %s" % result.header['status'])
    elif len(result.answers) == 0 and Base.defaults['server_rotate']:
        # check with next dns server
        result = Base.DnsRequest(name=name, qtype=qtype).req()
    if result.header['status'] != 'NOERROR':
        raise DNSError("dns query status: %s" % result.header['status'])
    return map(lambda x: x['data'],result.answers)
示例#4
0
def revlookup(name):
    "convenience routine for doing a reverse lookup of an address"
    if Base.defaults['server'] == []: Base.DiscoverNameServers()
    a = string.split(name, '.')
    a.reverse()
    b = string.join(a, '.') + '.in-addr.arpa'
    # this will only return one of any records returned.
    result = Base.DnsRequest(b, qtype='ptr').req()
    if result.header['status'] != 'NOERROR':
        raise StatusError("DNS query status: %s" % result.header['status'])
    elif len(result.answers) == 0:
        raise NoDataError("No PTR records for %s" % name)
    else:
        return result.answers[0]['data']