【问题标题】:python ipaddress()reverse_pointer equivalent for 3.4python ipaddress()reverse_pointer 等效于 3.4
【发布时间】:2015-07-12 12:02:26
【问题描述】:

我正在尝试从有效的 IPv6 地址获取反向 IPv6 arpa,但我想使用的功能仅在 Python3.5 中可用,并且 FreeBSD 端口仍在 Python3.4 上

In [1]: import ipaddress
In [3]: ipaddress.ip_address("2001:db8::1").reverse_pointer

AttributeError: 'IPv6Address' object has no attribute 'reverse_pointer'

获取反向 IPv6 arpa 的 Python3.4 等价物是什么?

ipaddress 3.5 manual page

【问题讨论】:

    标签: python dns ip ipv6


    【解决方案1】:

    您可以简单地下载 Python 3.5 的源代码并复制粘贴您需要的功能,

    def _reverse_pointer(self):
        """Return the reverse DNS pointer name for the IPv6 address.
    
        This implements the method described in RFC3596 2.5.
    
        """
        reverse_chars = self.exploded[::-1].replace(':', '')
        return '.'.join(reverse_chars) + '.ip6.arpa'
    

    可以如下使用,

    In [1]: import ipaddress
    In [2]: ip_addr = ipaddress.ip_address("2001:db8::1")
    In [3]: _reverse_pointer(ip_addr)
    Out[3]: '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
    

    【讨论】:

      猜你喜欢
      • 2021-07-22
      • 2012-06-28
      • 2018-12-26
      • 2017-03-07
      • 2015-01-22
      • 2014-10-20
      • 2012-07-18
      • 2019-01-31
      • 1970-01-01
      相关资源
      最近更新 更多