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
+13.7k Golang : Gin framework accept query string by post request example
+21.1k Golang : How to get time zone and load different time zone?
+62.5k Golang : Convert HTTP Response body to string
+10.5k Golang : Bubble sort example
+16.6k Golang : Read integer from file into array
+13.3k Golang : Get constant name from value
+5k Golang : Check if a word is countable or not
+50.7k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+25.7k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+9.4k Golang : Extract or copy items from map based on value
+31.3k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions