如何在 Python 中解析 SRV 记录?
-
19-09-2019 - |
题
不依赖本机库的东西会更好。
其他提示
使用 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}
不隶属于 StackOverflow