9

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

Sam Mussmann
  • 5,383
  • 1
  • 26
  • 42
Gili Nachum
  • 3,982
  • 2
  • 27
  • 29

4 Answers4

11

You could try the dnspython library:

ars
  • 106,073
  • 21
  • 135
  • 131
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.

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}
bstpierre
  • 26,946
  • 14
  • 63
  • 100
CHINTAN VADGAMA
  • 274
  • 2
  • 12
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']
bmaupin
  • 11,046
  • 4
  • 71
  • 74