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
+11.1k CodeIgniter : How to check if a session exist in PHP?
+10.5k Golang : Select region of interest with mouse click and crop from image
+9.6k Golang : Eroding and dilating image with OpenCV example
+6.8k Fix sudo yum hang problem with no output or error messages
+6.1k Linux/Unix : Commands that you need to be careful about
+12.2k Golang : Display list of countries and ISO codes
+14.3k Golang : How to convert a number to words
+6.5k Golang : Totalize or add-up an array or slice example
+22k Golang : Join arrays or slices example
+10.2k Golang : Embed secret text string into binary(executable) file
+9.3k Golang : Find the length of big.Int variable example
+5.2k Golang : Calculate half life decay example