SoFunction
Updated on 2025-03-05

Go language version ip2long function example

This article describes the ip2long function in the go language version. Share it for your reference. The specific analysis is as follows:

The ip2long function of the go language version introduced here will not verify the legitimacy of the IP.

Copy the codeThe code is as follows:
// Note: This function will not verify the legality of the IP
func Ip2Long(ip string) (ips string) {
    var ip_pieces = (ip, ".")
 ip_1, _ := (ip_pieces[0], 10, 32)
 ip_2, _ := (ip_pieces[1], 10, 32)
 ip_3, _ := (ip_pieces[2], 10, 32)
 ip_4, _ := (ip_pieces[3], 10, 32)
 var ip_bin string = ("%08b%08b%08b%08b", ip_1, ip_2, ip_3, ip_4)
 ip_int, _ := (ip_bin, 2, 64)
 return
}

I hope this article will be helpful to everyone's Go language programming.