How do I resolve an SRV record in Python?

后端 未结 4 1275
失恋的感觉
失恋的感觉 2020-12-18 00:43

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

4条回答
  •  渐次进展
    2020-12-18 00:53

    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}
    

提交回复
热议问题