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
+9.6k Golang : How to extract video or image files from html source code
+10.9k Golang : Command line file upload program to server example
+23k Golang : Test file read write permission example
+7k Golang : Levenshtein distance example
+7.5k Golang : Handling Yes No Quit query input
+13.1k Golang : Calculate elapsed years or months since a date
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+7.5k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+24k Golang : Use regular expression to validate domain name
+18.6k Golang : Aligning strings to right, left and center with fill example