feat: 服务器信息API

This commit is contained in:
Akkia
2022-05-17 20:16:46 +08:00
parent 76928b71d9
commit f5f71b252e
3 changed files with 161 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ import (
"math/rand"
"os"
"regexp"
"strings"
"time"
"unsafe"
@@ -68,3 +69,27 @@ func IPDesensitize(ipAddr string) string {
ipAddr = ipv6Desensitize(ipAddr)
return ipAddr
}
// SplitIPAddr 传入/分割的v4v6混合地址返回v4和v6地址与有效地址
func SplitIPAddr(v4v6Bundle string) (string, string, string) {
ipList := strings.Split(v4v6Bundle, "/")
ipv4 := ""
ipv6 := ""
validIP := ""
if len(ipList) > 1 {
// 双栈
ipv4 = ipList[0]
ipv6 = ipList[1]
validIP = ipv4
} else if len(ipList) == 1 {
// 仅ipv4|ipv6
if strings.Contains(ipList[0], ":") {
ipv6 = ipList[0]
validIP = ipv6
} else {
ipv4 = ipList[0]
validIP = ipv4
}
}
return ipv4, ipv6, validIP
}