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 : Tutorial on loading GOB and PEM files
+6.8k Golang : Calculate pivot points for a cross
+17.2k Golang : When to use init() function?
+21.7k Golang : Encrypt and decrypt data with TripleDES
+10.7k Golang : Get currencies exchange rates example
+8.7k Golang : Set or add headers for many or different handlers
+30.1k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+5.4k Unix/Linux : How to archive and compress entire directory ?
+15.1k Golang : How do I get the local IP (non-loopback) address ?
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+9k Golang : Populate or initialize struct with values example