- update is

master v1.0.37
李光春 2 years ago
parent 33e41cb5b1
commit 18b8be2356

@ -1,3 +1,3 @@
package goip
const Version = "1.0.36"
const Version = "1.0.37"

@ -32,7 +32,7 @@ require (
go.dtapp.net/gotime v1.0.5 // indirect
go.dtapp.net/gotrace_id v1.0.6 // indirect
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect
golang.org/x/net v0.0.0-20220919232410-f2f64ebce3c1 // indirect
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect

@ -84,8 +84,8 @@ golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 h1:a5Yg6ylndHHYJqIPrdq0AhvR6KTvDTAvgBtaidhEevY=
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220919232410-f2f64ebce3c1 h1:TWZxd/th7FbRSMret2MVQdlI8uT49QEtwZdvJrxjEHU=
golang.org/x/net v0.0.0-20220919232410-f2f64ebce3c1/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9 h1:asZqf0wXastQr+DudYagQS8uBO8bHKeYD1vbAvGmFL8=
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

51
is.go

@ -1,6 +1,10 @@
package goip
import "strings"
import (
"go.dtapp.net/gostring"
"net"
"strings"
)
var (
ipv4 = "IPV4"
@ -33,3 +37,48 @@ func (c *Client) isIpv4OrIpv6(ip string) string {
}
return ""
}
func IsIp(ipStr string) string {
if ipStr == "" {
return ""
}
// ipv4
if gostring.Contains(ipStr, "/32") {
cidr, _, _ := net.ParseCIDR(ipStr)
if cidr != nil {
return cidr.String()
}
}
// ipv6
if gostring.Contains(ipStr, "/128") {
cidr, _, _ := net.ParseCIDR(ipStr)
if cidr != nil {
return cidr.String()
}
}
// 解析
result := net.ParseIP(ipStr).String()
if result != "<nil>" {
return result
}
return ""
}
func IsIpConsistent(ipStr1, ipStr2 string) bool {
ip1Result := IsIp(ipStr1)
ip2Result := IsIp(ipStr2)
if ip1Result != "" && ip2Result != "" {
if ip1Result == ip2Result {
return true
}
}
return false
}

Loading…
Cancel
Save