9

不依赖本机库的东西会更好。

4

4 回答 4

10

你可以试试 dnspython 库:

于 2009-07-28T02:33:54.830 回答
8

twisted具有出色的纯 python 实现,请参阅twisted.names源代码(尤其是dns.py)。如果您不能使用他们的所有代码,也许您可​​以Record_SRV从该文件中提取并重新利用他们的类。

于 2009-07-27T17:14:00.277 回答
5

使用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}
于 2018-04-13T18:28:45.450 回答
1

使用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']
于 2013-02-27T22:25:01.700 回答