Something which doesn't rely on native libraries would be better.
Asked
Active
Viewed 1.2k times
4 Answers
11
You could try the dnspython library:
![](../../users/profiles/2611.webp)
ars
- 106,073
- 21
- 135
- 131
-
3Works thanks! import dns.resolver answers = dns.resolver.query('_xmpp-server._tcp.gmail.com', 'SRV') for rdata in answers: print str(rdata) – Gili Nachum Aug 29 '09 at 21:34
-
1This is a link only answer – oz123 Oct 05 '18 at 12:06
8
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.
![](../../users/profiles/95810.webp)
Alex Martelli
- 762,786
- 156
- 1,160
- 1,345
3
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}
![](../../users/profiles/67022.webp)
bstpierre
- 26,946
- 14
- 63
- 100
![](../../users/profiles/7876742.webp)
CHINTAN VADGAMA
- 274
- 2
- 12