mirror of
https://github.com/oneclickvirt/basics.git
synced 2025-09-26 20:51:16 +08:00
fix: 同时输出识别到的IPV4和IPV6的地址,方便融合怪主体进行调用
This commit is contained in:
@@ -44,11 +44,11 @@ func main() {
|
||||
preCheck := utils.CheckPublicAccess(3 * time.Second)
|
||||
var ipInfo string
|
||||
if preCheck.Connected && preCheck.StackType == "DualStack" {
|
||||
ipInfo, _, _ = network.NetworkCheck("both", false, language)
|
||||
_, _, ipInfo, _, _ = network.NetworkCheck("both", false, language)
|
||||
} else if preCheck.Connected && preCheck.StackType == "IPv4" {
|
||||
ipInfo, _, _ = network.NetworkCheck("ipv4", false, language)
|
||||
_, _, ipInfo, _, _ = network.NetworkCheck("ipv4", false, language)
|
||||
} else if preCheck.Connected && preCheck.StackType == "IPv6" {
|
||||
ipInfo, _, _ = network.NetworkCheck("ipv6", false, language)
|
||||
_, _, ipInfo, _, _ = network.NetworkCheck("ipv6", false, language)
|
||||
}
|
||||
res := system.CheckSystemInfo(language)
|
||||
fmt.Println("--------------------------------------------------")
|
||||
|
@@ -112,12 +112,12 @@ func processPrintIPInfo(ipVersion, language string, ipResult *model.IpInfo) stri
|
||||
// NetworkCheck 查询网络信息
|
||||
// checkType 可选 both ipv4 ipv6
|
||||
// language 暂时仅支持 en 或 zh
|
||||
func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (string, string, error) {
|
||||
func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (string, string, string, string, error) {
|
||||
if model.EnableLoger {
|
||||
InitLogger()
|
||||
defer Logger.Sync()
|
||||
}
|
||||
var ipInfo string
|
||||
var ipv4, ipv6, ipInfo string
|
||||
if checkType == "both" {
|
||||
ipInfoV4Result, ipInfoV6Result, err := baseinfo.RunIpCheck("both")
|
||||
if err != nil && model.EnableLoger {
|
||||
@@ -125,11 +125,13 @@ func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (
|
||||
}
|
||||
if ipInfoV4Result != nil {
|
||||
ipInfo += processPrintIPInfo("ipv4", language, ipInfoV4Result)
|
||||
ipv4 = ipInfoV4Result.Ip
|
||||
}
|
||||
if ipInfoV6Result != nil {
|
||||
ipInfo += processPrintIPInfo("ipv6", language, ipInfoV6Result)
|
||||
ipv6 = ipInfoV4Result.Ip
|
||||
}
|
||||
return ipInfo, "", nil
|
||||
return ipv4, ipv6, ipInfo, "", nil
|
||||
} else if checkType == "ipv4" {
|
||||
ipInfoV4Result, _, err := baseinfo.RunIpCheck("ipv4")
|
||||
if err != nil && model.EnableLoger {
|
||||
@@ -137,8 +139,9 @@ func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (
|
||||
}
|
||||
if ipInfoV4Result != nil {
|
||||
ipInfo += processPrintIPInfo("ipv4", language, ipInfoV4Result)
|
||||
ipv4 = ipInfoV4Result.Ip
|
||||
}
|
||||
return ipInfo, "", nil
|
||||
return ipv4, ipv6, ipInfo, "", nil
|
||||
} else if checkType == "ipv6" {
|
||||
ipInfoV6Result, _, err := baseinfo.RunIpCheck("ipv6")
|
||||
if err != nil && model.EnableLoger {
|
||||
@@ -146,8 +149,9 @@ func NetworkCheck(checkType string, enableSecurityCheck bool, language string) (
|
||||
}
|
||||
if ipInfoV6Result != nil {
|
||||
ipInfo += processPrintIPInfo("ipv6", language, ipInfoV6Result)
|
||||
ipv6 = ipInfoV6Result.Ip
|
||||
}
|
||||
return ipInfo, "", nil
|
||||
return ipv4, ipv6, ipInfo, "", nil
|
||||
}
|
||||
return "", "", fmt.Errorf("wrong in NetworkCheck")
|
||||
return "", "", "", "", fmt.Errorf("wrong in NetworkCheck")
|
||||
}
|
||||
|
@@ -8,8 +8,10 @@ import (
|
||||
// 本文件夹 network 修改需要同步 https://github.com/oneclickvirt/security 否则 goecs 无法使用
|
||||
func TestIpv4SecurityCheck(t *testing.T) {
|
||||
// 全项测试
|
||||
ipInfo, _, _ := NetworkCheck("both", false, "zh")
|
||||
ipv4, ipv6, ipInfo, _, _ := NetworkCheck("both", false, "zh")
|
||||
fmt.Println("--------------------------------------------------")
|
||||
fmt.Println(ipv4)
|
||||
fmt.Println(ipv6)
|
||||
fmt.Print(ipInfo)
|
||||
fmt.Println("--------------------------------------------------")
|
||||
}
|
||||
|
Reference in New Issue
Block a user