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
+37.8k Golang : Remove dashes(or any character) from string
+4.6k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+21.4k Golang : simulate tail -f or read last line from log file example
+17.2k Golang : Generate thumbnails from images
+12.8k Golang : How to check if your program is running in a terminal
+8.3k Golang : Changing a RGBA image number of channels with OpenCV
+7.4k Golang : Convert word to its plural form example
+72.6k Golang : How to return HTTP status code?
+5.6k Golang : How to validate ISBN?
+7.3k Golang: Prevent over writing file with md5 hash
+3.8k Facebook : How to place save to Facebook button on your website
+16.1k Golang : delete and modify XML file content