Created
January 15, 2019 07:50
-
-
Save bdss58/9453bdb240b94620ee1394baa44e9713 to your computer and use it in GitHub Desktop.
ip 字符串转整型 (golang)
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 ip2int(ip string) uint32 { | |
IP := net.ParseIP(ip) | |
if len(IP) >= 16 { | |
return binary.BigEndian.Uint32(IP[12:16]) | |
} else { | |
return 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment