【问题标题】:How do I resolve an SRV record in Python?如何在 Python 中解析 SRV 记录?
【发布时间】:2010-11-14 10:13:18
【问题描述】:

不依赖原生库的东西会更好。

【问题讨论】:

    标签: python networking dns srv


    【解决方案1】:

    【讨论】:

    • 工作谢谢! import dns.resolver answers = dns.resolver.query('_xmpp-server._tcp.gmail.com', 'SRV') for rdata in answers: print str(rdata)
    • 这只是一个链接回答
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      使用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}
      

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-04-25
          • 2016-12-12
          • 1970-01-01
          • 1970-01-01
          • 2013-01-17
          • 1970-01-01
          • 2011-04-15
          • 2010-11-10
          相关资源
          最近更新 更多