mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 07:50:14 +08:00
发布v2.2.10版本,更新内容请查看:https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN/addon-version-upgrade.md
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Package validate
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -62,6 +62,31 @@ func IsPublicIp(Ip string) bool {
|
||||
|
||||
}
|
||||
|
||||
// IsLocalIPAddr 检测 IP 地址字符串是否是内网地址
|
||||
func IsLocalIPAddr(ip string) bool {
|
||||
if "localhost" == ip {
|
||||
return true
|
||||
}
|
||||
return HasLocalIP(net.ParseIP(ip))
|
||||
}
|
||||
|
||||
// HasLocalIP 检测 IP 地址是否是内网地址
|
||||
func HasLocalIP(ip net.IP) bool {
|
||||
if ip.IsLoopback() {
|
||||
return true
|
||||
}
|
||||
|
||||
ip4 := ip.To4()
|
||||
if ip4 == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return ip4[0] == 10 || // 10.0.0.0/8
|
||||
(ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31) || // 172.16.0.0/12
|
||||
(ip4[0] == 169 && ip4[1] == 254) || // 169.254.0.0/16
|
||||
(ip4[0] == 192 && ip4[1] == 168) // 192.168.0.0/16
|
||||
}
|
||||
|
||||
// IsMobile 是否为手机号码
|
||||
func IsMobile(mobile string) bool {
|
||||
pattern := `^(1[2|3|4|5|6|7|8|9][0-9]\d{4,8})$`
|
||||
|
Reference in New Issue
Block a user