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
+4.7k Fix Google Analytics Redundant Hostnames problem
+8.1k Golang : Emulate NumPy way of creating matrix example
+6.2k Golang : Extract sub-strings
+5.3k Golang : Get S3 or CloudFront object or file information
+38.9k Golang : How to iterate over a []string(array)
+6.7k Golang : Calculate pivot points for a cross
+29.2k Golang : JQuery AJAX post data to server and send data back to client example
+29.1k Golang : missing Git command
+12.1k Golang : calculate elapsed run time
+21k Golang : How to force compile or remove object files first before rebuild?
+20.5k Golang : Read directory content with os.Open