8

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.

1 Answer 1

21

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
Sign up to request clarification or add additional context in comments.

2 Comments

Make sure to enter the IPv6 address as unicode or you may run into errors on Python 2
This also works for "IPv4-mapped IPv6 addresses": import ipaddress; print(ipaddress.ip_address('::ffff:192.0.2.128').exploded) -> 0000:0000:0000:0000:0000:ffff:c000:0280. Which is nice. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.