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
+7k Golang : Append and add item in slice
+4.5k Golang : fmt.Println prints out empty data from struct
+17.9k Golang : Clearing slice
+9.3k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+5.6k Golang : How to determine if request or crawl is from Google robots
+32.4k Golang : How to check if slice or array is empty?
+7.4k Android Studio : Image button and button example
+9.7k Golang : Simple image viewer with Go-GTK
+16.7k Golang : Convert IPv4 address to decimal number(base 10) or integer
+9.8k Golang : Natural string sorting example
+13.5k Golang : Save(pipe) HTTP response into a file
+12.5k Golang : unknown escape sequence error