How do I resolve an SRV record in Python?

无人久伴 提交于 2019-11-28 03:23:51

问题


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


回答1:


You could try the dnspython library:

  • http://www.dnspython.org/examples.html
  • http://www.dnspython.org/docs/1.7.1/html/dns.rdtypes.IN.SRV.SRV-class.html



回答2:


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.




回答3:


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']



回答4:


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}


来源:https://stackoverflow.com/questions/1189253/how-do-i-resolve-an-srv-record-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!