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
+16.2k Golang : Execute terminal command to remote machine example
+9.8k Golang : Setting variable value with ldflags
+16.6k Golang : Set up source IP address before making HTTP request
+12k Golang : calculate elapsed run time
+7.3k Golang : Shuffle strings array
+18.2k Golang : Read binary file into memory
+10.4k Golang : Flip coin example
+16.2k Golang : Send email and SMTP configuration example
+22.7k Golang : Gorilla mux routing example
+7.2k Golang : Create zip/ePub file without compression(use Store algorithm)
+20.6k Golang : Underscore or snake_case to camel case example
+12.9k Golang : Convert(cast) int to int64