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.2k Golang : Scan forex opportunities by Bollinger bands
+8.1k Golang : Grayscale Image
+30.6k Golang : Generate random string
+22k Golang : Convert string slice to struct and access with reflect example
+30.2k Golang : Get time.Duration in year, month, week or day
+12.5k Golang : How to check if a string starts or ends with certain characters or words?
+10.3k Golang : How to get quoted string into another string?
+11.5k Golang : Delay or limit HTTP requests example
+13.8k Android Studio : Password input and reveal password example
+4.8k Unix/Linux : How to pipe/save output of a command to file?
+11.8k Golang : Convert(cast) float to int
+8.5k Golang : Implementing class(object-oriented programming style)