Created
February 26, 2017 13:09
-
-
Save iCoolchar/1e76c9b897f25e9378f1963ceb6ea550 to your computer and use it in GitHub Desktop.
Golang ip to int
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func IP4toInt(IPv4Addr string) int64 { | |
IPv4Int := big.NewInt(0) | |
IPv4Int.SetBytes(net.ParseIP(IPv4Addr).To4()) | |
return IPv4Int.Int64() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
binary.LittleEndian.Uint32(net.ParseIP(IPv4Addr).To4())
Convert to a network order(little endian) 4 byte integer, that is broadly used in C network programming