How do I resolve an SRV record in Python?
Asked Answered
G

4

11

Something which doesn't rely on native libraries would be better.

Gormley answered 27/7, 2009 at 16:40 Comment(0)
B
11

You could try the dnspython library:

Bremerhaven answered 28/7, 2009 at 2:33 Comment(2)
Works thanks! import dns.resolver answers = dns.resolver.query('_xmpp-server._tcp.gmail.com', 'SRV') for rdata in answers: print str(rdata)Gormley
This is a link only answerZyrian
E
9

Using 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}
Ezzo answered 13/4, 2018 at 18:28 Comment(0)
H
7

twisted has an excellent pure-python implementation, see twisted.names sources (especially dns.py). If you can't use all of their code, maybe you can extract and repurpose their Record_SRV class from that file.

Hyperthermia answered 27/7, 2009 at 17:14 Comment(1)
Links are dead.Catt
S
1

Using 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']
Shrive answered 27/2, 2013 at 22:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.