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
+11.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+5.1k Golang : Convert Chinese UTF8 characters to Pin Yin
+6.4k Golang : Individual and total number of words counter example
+28.7k Get client IP Address in Go
+11.4k Golang : HTTP response JSON encoded data
+6.8k Javascript : Put image into Chrome browser's console
+7.3k Golang : Ackermann function example
+7.3k Swift : Convert (cast) Character to Integer?
+11.8k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+3.5k Javascript : Detect when console is activated and do something about it
+7.4k Golang : On lambda, anonymous, inline functions and function literals
+4.4k Unix/Linux/MacOSx : How to remove an environment variable ?