package main import ( "fmt" "net" "reflect" "github.com/thinkeridea/go-extend/exnet" ) func main() { ip := "192.168.1.1" n, _ := exnet.IPString2Long(ip) s, _ := exnet.Long2IPString(n) fmt.Println(n, s == ip) Ip1 := net.ParseIP(ip) // 会得到一个16字节的byte,主要为了兼容ipv6 n, _ = exnet.IP2Long(Ip1) Ip2, _ := exnet.Long2IP(n) fmt.Println(n, reflect.DeepEqual(Ip1[12:], Ip2)) }