Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand ipv6 address using python?

I want to convert shorthand notation of ipv6 address to longhand notation of ipv6 addressing format; I know we can perform various operations on ip addresses using ipaddress library. For example I want to convert ::abc:7:def to 0000:0000:0000:0000:0000:0abc:0007:0def.

like image 387
pankmish Avatar asked Nov 28 '16 05:11

pankmish


1 Answers

You're looking for the exploded property of the IPv6Address object. You get this through calling ipaddress.ip_address:

> import ipaddress
> addr = ipaddress.ip_address('::abc:7:def')
> print(addr.exploded)
0000:0000:0000:0000:0000:0abc:0007:0def
like image 128
cwallenpoole Avatar answered Sep 17 '22 18:09

cwallenpoole