Exemple #1
0
def dns_PTR_resolve(addr, resolve):
    "resolve asynchronously an numeric IP address to a named one"

    def resolved(request):
        if request.dns_resources:
            resolve((request.dns_resources[0], addr[1]))
        else:
            resolve(None)

    dns_client.lookup((ip_peer.in_addr_arpa(addr[0]), 'PTR'), resolved)
def dns_PTR_resolve (addr, resolve):
        "resolve asynchronously an numeric IP address to a named one"
        def resolved (request):
                if request.dns_resources:
                        resolve ((request.dns_resources[0], addr[1]))
                else:
                        resolve (None)
        
        dns_client.lookup ((
                ip_peer.in_addr_arpa (addr[0]), 'PTR'
                ), resolved)
Exemple #3
0
def dns_double_lookup(addr, resolve):
    "resolve the name of a numeric IP address if it is reversed"

    def resolve_PTR(request):
        if request.dns_resources:
            name = request.dns_resources[0]

            def resolve_A(request):
                if (request.dns_resources
                        and request.dns_resources[0] == addr[0]):
                    resolve((name, addr[1]))
                else:
                    resolve(None)

            dns_client.lookup((name, 'A'), resolve_A)
        else:
            resolve(None)

    dns_client.lookup((ip_peer.in_addr_arpa(addr[0]), 'PTR'), resolve_PTR)
def dns_double_lookup (addr, resolve):
        "resolve the name of a numeric IP address if it is reversed"
        def resolve_PTR (request):
                if request.dns_resources:
                        name = request.dns_resources[0]
                        def resolve_A (request):
                                if (
                                        request.dns_resources and 
                                        request.dns_resources[0] == addr[0]
                                        ):
                                        resolve ((name, addr[1]))
                                else:
                                        resolve (None)

                        dns_client.lookup ((name, 'A'), resolve_A)
                else:
                        resolve (None)
        
        dns_client.lookup ((
                ip_peer.in_addr_arpa (addr[0]), 'PTR'
                ), resolve_PTR)
from allegra import loginfo, ip_peer
        
s = ip_peer.host_ip
loginfo.log ('%r' % s)
loginfo.log ('%r' % ip_peer.is_ip (s))
l = ip_peer.ip2long (s)
loginfo.log ('%r' % l)
loginfo.log ('%r' % (ip_peer.long2ip (l)))
loginfo.log ('%r' % ip_peer.in_addr_arpa (s))
                )
        sys.exit (1)
        
servers = None
if len (sys.argv) > 2:
        question = tuple (sys.argv[1:3])
        if len (sys.argv) > 3:
                servers = sys.argv[3:]
else:
        question = (sys.argv[1], 'A')
def resolved (request):
        model = list (request.dns_question)
        if request.dns_resources == None:
                model.append ('')
        elif len (request.dns_resources) > 1:
                model.append (netstring.encode (
                        request.dns_resources
                        ))
        elif request.dns_resources:
                model.append (request.dns_resources[0])
        else:
                model.append ('')
        model.append (request.dns_peer[0])
        loginfo.log (netstring.encode (model))
        
if question[1] == 'PTR':
        question = (ip_peer.in_addr_arpa (question[0]), question[1])
dns_client.lookup (question, resolved, servers)
async_loop.dispatch ()
assert None == finalization.collect ()
sys.exit (0)
Exemple #7
0
from allegra import loginfo, ip_peer

s = ip_peer.host_ip
loginfo.log('%r' % s)
loginfo.log('%r' % ip_peer.is_ip(s))
l = ip_peer.ip2long(s)
loginfo.log('%r' % l)
loginfo.log('%r' % (ip_peer.long2ip(l)))
loginfo.log('%r' % ip_peer.in_addr_arpa(s))