python ipv6 to cidr给出了错误的掩码

时间:2015-05-02 05:05:00

标签: python ipv6 cidr

我正在尝试将ipv6地址转换为cidr格式,但网络掩码似乎不正确。它应该是/ 64但我得到/ 128

代码:

import ipaddress
ipv6 = '2001:19f0:5800:8561:5400:ff:fe07:cae5'
iv6cidr = ipaddress.ip_interface(ipv6)
print(iv6cidr)

输出:

2001:19f0:5800:8561:5400:ff:fe07:cae5/128

预期产出:

2001:19f0:5800:8561:5400:ff:fe07:cae5/64

我不是IPv6向导,但我找到的每个子网计算器都说/ 64

如何以cidr格式获取正确的IPv6网络掩码?

的ifconfig:

vtnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=6c03bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
        ether 56:00:00:07:ca:e5
        inet 108.61.169.203 netmask 0xfffffe00 broadcast 108.61.169.255
        inet6 fe80::5400:ff:fe07:cae5%vtnet0 prefixlen 64 scopeid 0x1
        inet6 2001:19f0:5800:8561::64 prefixlen 64
        inet6 2001:19f0:5800:8561:5400:ff:fe07:cae5 prefixlen 64 autoconf
        nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
        media: Ethernet 10Gbase-T <full-duplex>
        status: active

1 个答案:

答案 0 :(得分:1)

/ 128是正确的。您没有在输入中指定前缀长度,因此代码必须猜测您的意思。它所做的猜测是最正确的:例如,可以在回送接口上使用单个地址。显示/ 64将是一个假设。