ai update.

This commit is contained in:
2025-10-03 19:55:20 +08:00
parent 0401a39a94
commit 464617626b
15 changed files with 374 additions and 378 deletions

View File

@@ -1,3 +1,5 @@
// Package utils 提供通用工具函数
// 包括数据类型转换、时间处理、网络工具等
package utils
import (
@@ -13,6 +15,9 @@ import (
"strings"
)
// IsPublicIP 判断是否为公网IP
// ipString: IP地址字符串
// 返回: 是否为公网IP
func IsPublicIP(ipString string) bool {
ip := net.ParseIP(ipString)
if ip.IsLoopback() || ip.IsLinkLocalMulticast() || ip.IsLinkLocalUnicast() {
@@ -20,11 +25,11 @@ func IsPublicIP(ipString string) bool {
}
if ip4 := ip.To4(); ip4 != nil {
switch true {
case ip4[0] == 10:
case ip4[0] == 10: // 10.0.0.0/8
return false
case ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31:
case ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31: // 172.16.0.0/12
return false
case ip4[0] == 192 && ip4[1] == 168:
case ip4[0] == 192 && ip4[1] == 168: // 192.168.0.0/16
return false
default:
return true
@@ -33,7 +38,8 @@ func IsPublicIP(ipString string) bool {
return false
}
// Get Location IP .
// GetLocationIP 获取本机IP地址
// 返回: 本机IP地址
func GetLocationIP() (localIp string) {
localIp = "127.0.0.1"
// Get all network interfaces