Python : Convert IPv6 address to decimal and back to IPv6
Problem :
Need to convert IPv6 address to decimal number and convert back to IPv6. How to do that?
Solution :
Use the netaddr.IPAddress()
function to convert IPv6 to decimal and back to IPv6.
For example :
// convert decimal number to IPv6 address
import netaddr
print str(netaddr.IPAddress(338288524927261089654163772891438416681))
Output :
fe80::202:b3ff:fe1e:8329
// convert IPv6 address to decimal number
import netaddr
print int(netaddr.IPAddress('fe80::202:b3ff:fe1e:8329'))
Output :
338288524927261089654163772891438416681
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.3k Linux/Unix : Commands that you need to be careful about
+13.4k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+8k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+11k Golang : Natural string sorting example
+13.6k Golang : How to get year, month and day?
+18.6k Golang : How to remove certain lines from a file
+6.4k Golang : Selection sort example
+23.7k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+11.8k Golang : Calculations using complex numbers example
+9.6k Golang : Scramble and unscramble text message by randomly replacing words
+8.3k How to show different content from website server when AdBlock is detected?
+5.7k Swift : Get substring with rangeOfString() function example