mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
feat: 服务器信息API
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user