Pregunta

Algo que no se basa en las bibliotecas nativas sería mejor.

Otros consejos

trenzado tiene una excelente aplicación pura-pitón, consulte twisted.names fuentes (especialmente dns.py ). Si no puede utilizar todo su código, tal vez se puede extraer y cambiar la finalidad de su clase Record_SRV de ese archivo.

pydns :

import DNS
DNS.ParseResolvConf()
srv_req = DNS.Request(qtype = 'srv')
srv_result = srv_req.req('_ldap._tcp.example.org')

for result in srv_result.answers:
    if result['typename'] == 'SRV':
        print result['data']

dnspython :

>>> import dns.resolver
>>> domain='jabberzac.org'
>>> srvInfo = {}
>>> srv_records=dns.resolver.query('_xmpp-client._tcp.'+domain, 'SRV')
>>> for srv in srv_records:
...     srvInfo['weight']   = srv.weight
...     srvInfo['host']     = str(srv.target).rstrip('.')
...     srvInfo['priority'] = srv.priority
...     srvInfo['port']     = srv.port
... 
>>> print srvInfo
{'priority': 0, 'host': 'xmpp.jabberzac.org', 'port': 5222, 'weight': 0}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top