如何使用python扩展ipv6地址?
How to expand ipv6 address using python?
我想将 ipv6 地址的 shorthand 符号转换为 ipv6 地址格式的普通符号;我知道我们可以使用 ipaddress
库对 ip 地址执行各种操作。例如我想将 ::abc:7:def
转换为 0000:0000:0000:0000:0000:0abc:0007:0def
.
您正在寻找 IPv6Address
对象的 exploded
属性。您可以通过调用 ipaddress.ip_address
:
获得此信息
> import ipaddress
> addr = ipaddress.ip_address('::abc:7:def')
> print(addr.exploded)
0000:0000:0000:0000:0000:0abc:0007:0def
我想将 ipv6 地址的 shorthand 符号转换为 ipv6 地址格式的普通符号;我知道我们可以使用 ipaddress
库对 ip 地址执行各种操作。例如我想将 ::abc:7:def
转换为 0000:0000:0000:0000:0000:0abc:0007:0def
.
您正在寻找 IPv6Address
对象的 exploded
属性。您可以通过调用 ipaddress.ip_address
:
> import ipaddress
> addr = ipaddress.ip_address('::abc:7:def')
> print(addr.exploded)
0000:0000:0000:0000:0000:0abc:0007:0def