|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|