mtchuyen / Golang-Tips

Tips in Golang programming
3 stars 2 forks source link

Golang ip <-> int conversion #19

Open mtchuyen opened 2 years ago

mtchuyen commented 2 years ago

https://gist.github.com/ammario/649d4c0da650162efd404af23e25b86b

https://www.socketloop.com/tutorials/golang-convert-ipv4-address-to-decimal-number-base-10-or-integer

https://www.socketloop.com/tutorials/golang-convert-ip-address-string-to-long-unsigned-32-bit-integer

Python: Convert IP address to integer and vice versa

mtchuyen commented 3 weeks ago

IPv6 to Number

IPv6 to Big Int

IPv6 Big Int Convert
2001:ee0:491d:1690:c06e:9ea2:d3ee:178f 42540789885446268207134891374906578831
2402:800:bace:9f19:e962:ab7b:eed0:a64b 47862754759064872173024873757218481739
2402:800:63b8:a2cf:6dfa:502a:d061:c202 47862754732113097466050743092188922370

IPv6 to UInt32

uint MaxValue = 4294967295;

Code: https://go.dev/play/p/qJKwf0YnxxX IPv6 UInt32
2402:800:6379:f008:193a:5e4d:888c:a21b 2542791149
2001:ee0:22c:8693:9817:4e64:abce:80f1 2647131171
2401:d800:5380:8bac:7cb8:5284:b544:c9fd 3783207997
2402:9d80:248:55b:e9d6:112a:c641:7107 4180944089
2402:9d80:432:fa7c:ad05:631a:d53c:6efb 575439526
2402:800:b00e:79c3:f5fe:519e:c5b5:2f1e 1490888378
mtchuyen commented 3 weeks ago

IPv4 to UInt32

IPv4 to-UInt32
171.252.154.27 2885458459
171.247.104.89 2885118041
14.190.32.131 247341187
14.186.13.72 247074120
14.232.132.174 250119342
42.113.157.187 712089019
42.119.190.37 712490533
42.119.190.37 712490533
42.116.228.235 712303851
116.111.184.5 1953478661
113.160.248.145 1906374801
27.67.20.74 457380938