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
+3.6k Adding Skype actions such as call and chat into web page examples
+38.8k Golang : How do I convert int to uint8?
+19.2k Golang : Pipe output from one os.Exec(shell command) to another command
+7.9k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+24.6k Mac/Linux and Golang : Fix bind: address already in use error
+10.8k Golang : Simple client-server HMAC authentication without SSL example
+26.1k Golang : Record voice(audio) from microphone to .WAV file
+15.3k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+19.7k Curl usage examples with Golang
+7.6k Golang : Set or add headers for many or different handlers
+13.5k Golang : Save(pipe) HTTP response into a file
+7.3k Golang: Prevent over writing file with md5 hash