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
+51.9k Golang : How to get struct field and value by name
+33.3k Golang : All update packages with go get command
+32k Golang : Copy directory - including sub-directories and files
+19.3k Golang : Close channel after ticker stopped example
+8.8k Golang : Gonum standard normal random numbers example
+6.8k Web : How to see your website from different countries?
+5.1k Golang : How to deal with configuration data?
+5.8k PageSpeed : Clear or flush cache on web server
+10k Golang : Convert file content to Hex
+9.2k Golang : Extract or copy items from map based on value
+12.2k Golang : Forwarding a local port to a remote server example
+11.1k Golang : Find age or leap age from date of birth example