mirror of
https://github.com/oneclickvirt/ecs.git
synced 2025-09-30 21:22:11 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8af46d4bfb | ||
![]() |
e8fdbee3e4 | ||
![]() |
6cbd20fc90 | ||
![]() |
25c0b2ba95 | ||
![]() |
f16c0e7bcf | ||
![]() |
12e29bc105 | ||
![]() |
f7a7e34b34 | ||
![]() |
4d7049c9b8 | ||
![]() |
ad61caf1d2 | ||
![]() |
f84cbe2078 |
25
README.md
25
README.md
@@ -1,11 +1,21 @@
|
|||||||
# ecs
|
# ecs
|
||||||
|
|
||||||
[](https://github.com/oneclickvirt/ecs/actions/workflows/main.yaml)
|
[](https://github.com/oneclickvirt/ecs/actions/workflows/main.yaml) [](https://www.spiritlhl.net/)
|
||||||
|
|
||||||
融合怪测评脚本 - GO重构版本
|
融合怪测评脚本 - GO重构版本 - 由于未正式发版,如有问题请issues反馈
|
||||||
|
|
||||||
Shell版本: https://github.com/spiritLHLS/ecs
|
Shell版本: https://github.com/spiritLHLS/ecs
|
||||||
|
|
||||||
|
## 适配系统和架构
|
||||||
|
|
||||||
|
已支持的架构: x86_64、i386、arm64
|
||||||
|
|
||||||
|
待支持的架构(有依赖包不支持该架构): s390x
|
||||||
|
|
||||||
|
已支持的系统: Linux、Windows
|
||||||
|
|
||||||
|
待支持的系统(存在硬件测试BUG未修复): MacOS
|
||||||
|
|
||||||
## 功能
|
## 功能
|
||||||
|
|
||||||
- [x] 系统基础信息查询[自研[basics](https://github.com/oneclickvirt/basics)、[gostun](https://github.com/oneclickvirt/gostun)]
|
- [x] 系统基础信息查询[自研[basics](https://github.com/oneclickvirt/basics)、[gostun](https://github.com/oneclickvirt/gostun)]
|
||||||
@@ -20,14 +30,9 @@ Shell版本: https://github.com/spiritLHLS/ecs
|
|||||||
- [x] 三网回程测试[借鉴[zhanghanyun/backtrace](https://github.com/zhanghanyun/backtrace)二次开发至于[oneclickvirt/backtrace](https://github.com/oneclickvirt/backtrace)]
|
- [x] 三网回程测试[借鉴[zhanghanyun/backtrace](https://github.com/zhanghanyun/backtrace)二次开发至于[oneclickvirt/backtrace](https://github.com/oneclickvirt/backtrace)]
|
||||||
- [x] 三网路由测试[借鉴[NTrace-core](https://github.com/nxtrace/NTrace-core)二次开发至于[nt3](https://github.com/oneclickvirt/nt3)]
|
- [x] 三网路由测试[借鉴[NTrace-core](https://github.com/nxtrace/NTrace-core)二次开发至于[nt3](https://github.com/oneclickvirt/nt3)]
|
||||||
- [x] 测试网速[基于[speedtest.net-爬虫](https://github.com/spiritLHLS/speedtest.net-CN-ID)、[speedtest.cn-爬虫](https://github.com/spiritLHLS/speedtest.cn-CN-ID)的数据,借鉴[speedtest-go](https://github.com/showwin/speedtest-go)二次开发至于[oneclickvirt/speedtest](https://github.com/oneclickvirt/speedtest)]
|
- [x] 测试网速[基于[speedtest.net-爬虫](https://github.com/spiritLHLS/speedtest.net-CN-ID)、[speedtest.cn-爬虫](https://github.com/spiritLHLS/speedtest.cn-CN-ID)的数据,借鉴[speedtest-go](https://github.com/showwin/speedtest-go)二次开发至于[oneclickvirt/speedtest](https://github.com/oneclickvirt/speedtest)]
|
||||||
|
- [x] 测试三网Ping值[借鉴[ecsspeed](https://github.com/spiritLHLS/ecsspeed)的逻辑二次开发至于[pingtest](https://github.com/oneclickvirt/pingtest)]
|
||||||
|
|
||||||
## TODO
|
## Linux上使用的说明
|
||||||
|
|
||||||
- [ ] 测试三网Ping值[借鉴[ecsspeed](https://github.com/spiritLHLS/ecsspeed)的逻辑二次开发]
|
|
||||||
|
|
||||||
## Linux/macOS上使用的说明
|
|
||||||
|
|
||||||
开发中,勿要使用
|
|
||||||
|
|
||||||
下载脚本
|
下载脚本
|
||||||
|
|
||||||
@@ -71,6 +76,7 @@ shell脚本的说明
|
|||||||
Available commands:
|
Available commands:
|
||||||
|
|
||||||
./goecs.sh env Check and Install package:
|
./goecs.sh env Check and Install package:
|
||||||
|
sudo (Almost all unix-like systems have it.)
|
||||||
tar (Almost all unix-like systems have it.)
|
tar (Almost all unix-like systems have it.)
|
||||||
unzip (Almost all unix-like systems have it.)
|
unzip (Almost all unix-like systems have it.)
|
||||||
dd (Almost all unix-like systems have it.)
|
dd (Almost all unix-like systems have it.)
|
||||||
@@ -78,6 +84,7 @@ Available commands:
|
|||||||
sysbench (Almost all unix-like systems can be installed through the system's package manager.)
|
sysbench (Almost all unix-like systems can be installed through the system's package manager.)
|
||||||
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.)
|
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.)
|
||||||
speedtest (Use the officially provided binaries for more accurate test results.)
|
speedtest (Use the officially provided binaries for more accurate test results.)
|
||||||
|
ping (Use the officially provided binaries for more accurate test results.)
|
||||||
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested.
|
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested.
|
||||||
./goecs.sh install Install goecs command
|
./goecs.sh install Install goecs command
|
||||||
./goecs.sh upgrade Upgrade goecs command
|
./goecs.sh upgrade Upgrade goecs command
|
||||||
|
2
go.mod
2
go.mod
@@ -14,6 +14,7 @@ require (
|
|||||||
github.com/oneclickvirt/gostun v0.0.3-20240702054621
|
github.com/oneclickvirt/gostun v0.0.3-20240702054621
|
||||||
github.com/oneclickvirt/memorytest v0.0.2-20240702031042
|
github.com/oneclickvirt/memorytest v0.0.2-20240702031042
|
||||||
github.com/oneclickvirt/nt3 v0.0.3-20240702132013
|
github.com/oneclickvirt/nt3 v0.0.3-20240702132013
|
||||||
|
github.com/oneclickvirt/pingtest v0.0.4-20240703142340
|
||||||
github.com/oneclickvirt/portchecker v0.0.1-20240624155429
|
github.com/oneclickvirt/portchecker v0.0.1-20240624155429
|
||||||
github.com/oneclickvirt/security v0.0.4-20240702055848
|
github.com/oneclickvirt/security v0.0.4-20240702055848
|
||||||
github.com/oneclickvirt/speedtest v0.0.6-20240702134926
|
github.com/oneclickvirt/speedtest v0.0.6-20240702134926
|
||||||
@@ -45,6 +46,7 @@ require (
|
|||||||
github.com/magiconair/properties v1.8.7 // indirect
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/nxtrace/NTrace-core v1.3.1 // indirect
|
github.com/nxtrace/NTrace-core v1.3.1 // indirect
|
||||||
|
2
go.sum
2
go.sum
@@ -95,6 +95,8 @@ github.com/oneclickvirt/memorytest v0.0.2-20240702031042 h1:j+LsjOh5glYiidqtSqjZ
|
|||||||
github.com/oneclickvirt/memorytest v0.0.2-20240702031042/go.mod h1:+YNzy+NeVg61d0kNwSyVDqHyVtKzjuRe1NvMzsDLg0I=
|
github.com/oneclickvirt/memorytest v0.0.2-20240702031042/go.mod h1:+YNzy+NeVg61d0kNwSyVDqHyVtKzjuRe1NvMzsDLg0I=
|
||||||
github.com/oneclickvirt/nt3 v0.0.3-20240702132013 h1:zPI/zqqCraIVwRnYz07hMkBKDRJVkEBb6gZpZ4M9CjI=
|
github.com/oneclickvirt/nt3 v0.0.3-20240702132013 h1:zPI/zqqCraIVwRnYz07hMkBKDRJVkEBb6gZpZ4M9CjI=
|
||||||
github.com/oneclickvirt/nt3 v0.0.3-20240702132013/go.mod h1:UojPmtangn17TiQaDccVrZbn6sZwJOtzBgg3idp68cA=
|
github.com/oneclickvirt/nt3 v0.0.3-20240702132013/go.mod h1:UojPmtangn17TiQaDccVrZbn6sZwJOtzBgg3idp68cA=
|
||||||
|
github.com/oneclickvirt/pingtest v0.0.4-20240703142340 h1:012W8Ly6ALISwIL5cYFM8O1ZLSc9l+Z2hHUCscMemms=
|
||||||
|
github.com/oneclickvirt/pingtest v0.0.4-20240703142340/go.mod h1:IU9RzZpS5tfP2kcFd2sw2fE80BgtiMUK8jp6qnN/0cY=
|
||||||
github.com/oneclickvirt/portchecker v0.0.1-20240624155429 h1:+wapaOcFrg1iWJDhBKThDzppyIMY7hWxK7F5RBkZg4o=
|
github.com/oneclickvirt/portchecker v0.0.1-20240624155429 h1:+wapaOcFrg1iWJDhBKThDzppyIMY7hWxK7F5RBkZg4o=
|
||||||
github.com/oneclickvirt/portchecker v0.0.1-20240624155429/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k=
|
github.com/oneclickvirt/portchecker v0.0.1-20240624155429/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k=
|
||||||
github.com/oneclickvirt/security v0.0.4-20240702055848 h1:UCfjfoslcfKhCvJm37jQmhJ+O8d4lL+uvBJVcLAXc2s=
|
github.com/oneclickvirt/security v0.0.4-20240702055848 h1:UCfjfoslcfKhCvJm37jQmhJ+O8d4lL+uvBJVcLAXc2s=
|
||||||
|
31
goecs.go
31
goecs.go
@@ -20,8 +20,11 @@ import (
|
|||||||
gostunmodel "github.com/oneclickvirt/gostun/model"
|
gostunmodel "github.com/oneclickvirt/gostun/model"
|
||||||
memorytestmodel "github.com/oneclickvirt/memorytest/memory"
|
memorytestmodel "github.com/oneclickvirt/memorytest/memory"
|
||||||
nt3model "github.com/oneclickvirt/nt3/model"
|
nt3model "github.com/oneclickvirt/nt3/model"
|
||||||
|
ptmodel "github.com/oneclickvirt/pingtest/model"
|
||||||
|
"github.com/oneclickvirt/pingtest/pt"
|
||||||
"github.com/oneclickvirt/portchecker/email"
|
"github.com/oneclickvirt/portchecker/email"
|
||||||
speedtestmodel "github.com/oneclickvirt/speedtest/model"
|
speedtestmodel "github.com/oneclickvirt/speedtest/model"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -33,8 +36,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ecsVersion = "v0.0.31"
|
ecsVersion = "v0.0.33"
|
||||||
menuMode bool
|
menuMode bool
|
||||||
|
onlyChinaTest bool
|
||||||
input, choice string
|
input, choice string
|
||||||
showVersion bool
|
showVersion bool
|
||||||
enableLogger bool
|
enableLogger bool
|
||||||
@@ -48,7 +52,7 @@ var (
|
|||||||
width = 82
|
width = 82
|
||||||
basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus bool
|
basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus bool
|
||||||
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus bool
|
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus bool
|
||||||
backtraceStatus, nt3Status, speedTestStatus bool
|
backtraceStatus, nt3Status, speedTestStatus, pingTestStatus bool
|
||||||
filePath = "goecs.txt"
|
filePath = "goecs.txt"
|
||||||
enabelUpload = true
|
enabelUpload = true
|
||||||
help bool
|
help bool
|
||||||
@@ -100,11 +104,14 @@ func main() {
|
|||||||
memorytestmodel.EnableLoger = true
|
memorytestmodel.EnableLoger = true
|
||||||
disktestmodel.EnableLoger = true
|
disktestmodel.EnableLoger = true
|
||||||
commediatests.EnableLoger = true
|
commediatests.EnableLoger = true
|
||||||
|
ptmodel.EnableLoger = true
|
||||||
backtraceori.EnableLoger = true
|
backtraceori.EnableLoger = true
|
||||||
nt3model.EnableLoger = true
|
nt3model.EnableLoger = true
|
||||||
speedtestmodel.EnableLoger = true
|
speedtestmodel.EnableLoger = true
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
|
http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fecs&count_bg=%2357DEFF&title_bg=%23000000&icon=cliqz.svg&icon_color=%23E7E7E7&title=hits&edge_flat=false")
|
||||||
|
}()
|
||||||
if menuMode {
|
if menuMode {
|
||||||
basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus = false, false, false, false
|
basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus = false, false, false, false
|
||||||
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus = false, false, false, false
|
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus = false, false, false, false
|
||||||
@@ -156,6 +163,7 @@ func main() {
|
|||||||
backtraceStatus = true
|
backtraceStatus = true
|
||||||
nt3Status = true
|
nt3Status = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
|
onlyChinaTest = utils.CheckChina(enableLogger)
|
||||||
break Loop
|
break Loop
|
||||||
case "2":
|
case "2":
|
||||||
basicStatus = true
|
basicStatus = true
|
||||||
@@ -215,6 +223,7 @@ func main() {
|
|||||||
backtraceStatus = true
|
backtraceStatus = true
|
||||||
nt3Status = true
|
nt3Status = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
|
pingTestStatus = true
|
||||||
break Loop
|
break Loop
|
||||||
default:
|
default:
|
||||||
if language == "zh" {
|
if language == "zh" {
|
||||||
@@ -288,7 +297,7 @@ func main() {
|
|||||||
emailInfo = email.EmailCheck()
|
emailInfo = email.EmailCheck()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if utTestStatus {
|
if utTestStatus && !onlyChinaTest {
|
||||||
wg1.Add(1)
|
wg1.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg1.Done()
|
defer wg1.Done()
|
||||||
@@ -296,13 +305,13 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
output = utils.PrintAndCapture(func() {
|
output = utils.PrintAndCapture(func() {
|
||||||
if commTestStatus {
|
if commTestStatus && !onlyChinaTest {
|
||||||
utils.PrintCenteredTitle("御三家流媒体解锁", width)
|
utils.PrintCenteredTitle("御三家流媒体解锁", width)
|
||||||
commediatest.ComMediaTest(language)
|
commediatest.ComMediaTest(language)
|
||||||
}
|
}
|
||||||
}, tempOutput, output)
|
}, tempOutput, output)
|
||||||
output = utils.PrintAndCapture(func() {
|
output = utils.PrintAndCapture(func() {
|
||||||
if utTestStatus {
|
if utTestStatus && !onlyChinaTest {
|
||||||
utils.PrintCenteredTitle("跨国流媒体解锁", width)
|
utils.PrintCenteredTitle("跨国流媒体解锁", width)
|
||||||
wg1.Wait()
|
wg1.Wait()
|
||||||
fmt.Printf(mediaInfo)
|
fmt.Printf(mediaInfo)
|
||||||
@@ -323,18 +332,24 @@ func main() {
|
|||||||
}, tempOutput, output)
|
}, tempOutput, output)
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
output = utils.PrintAndCapture(func() {
|
output = utils.PrintAndCapture(func() {
|
||||||
if backtraceStatus {
|
if backtraceStatus && !onlyChinaTest {
|
||||||
utils.PrintCenteredTitle("三网回程线路检测", width)
|
utils.PrintCenteredTitle("三网回程线路检测", width)
|
||||||
backtrace.BackTrace()
|
backtrace.BackTrace()
|
||||||
}
|
}
|
||||||
}, tempOutput, output)
|
}, tempOutput, output)
|
||||||
// nexttrace 在win上不支持检测,报错 bind: An invalid argument was supplied.
|
// nexttrace 在win上不支持检测,报错 bind: An invalid argument was supplied.
|
||||||
output = utils.PrintAndCapture(func() {
|
output = utils.PrintAndCapture(func() {
|
||||||
if nt3Status {
|
if nt3Status && !onlyChinaTest {
|
||||||
utils.PrintCenteredTitle("三网回程路由检测", width)
|
utils.PrintCenteredTitle("三网回程路由检测", width)
|
||||||
ntrace.TraceRoute3(language, nt3Location, nt3CheckType)
|
ntrace.TraceRoute3(language, nt3Location, nt3CheckType)
|
||||||
}
|
}
|
||||||
}, tempOutput, output)
|
}, tempOutput, output)
|
||||||
|
output = utils.PrintAndCapture(func() {
|
||||||
|
if onlyChinaTest || pingTestStatus {
|
||||||
|
utils.PrintCenteredTitle("三网ICMP的PING值检测", width)
|
||||||
|
pt.PingTest()
|
||||||
|
}
|
||||||
|
}, tempOutput, output)
|
||||||
}
|
}
|
||||||
output = utils.PrintAndCapture(func() {
|
output = utils.PrintAndCapture(func() {
|
||||||
if speedTestStatus {
|
if speedTestStatus {
|
||||||
|
16
goecs.sh
16
goecs.sh
@@ -246,6 +246,10 @@ env_check() {
|
|||||||
check_cdn_file
|
check_cdn_file
|
||||||
_green "Update system manager."
|
_green "Update system manager."
|
||||||
$PACKAGE_UPDATE command 2>/dev/null
|
$PACKAGE_UPDATE command 2>/dev/null
|
||||||
|
if ! command -v sudo >/dev/null 2>&1; then
|
||||||
|
_green "Installing sudo"
|
||||||
|
$PACKAGE_INSTALL sudo
|
||||||
|
fi
|
||||||
if ! command -v tar >/dev/null 2>&1; then
|
if ! command -v tar >/dev/null 2>&1; then
|
||||||
_green "Installing tar"
|
_green "Installing tar"
|
||||||
$PACKAGE_INSTALL tar
|
$PACKAGE_INSTALL tar
|
||||||
@@ -300,10 +304,20 @@ env_check() {
|
|||||||
echo "rm -rf /usr/bin/speedtest-go"
|
echo "rm -rf /usr/bin/speedtest-go"
|
||||||
_blue "to uninstall speedtest and speedtest-go"
|
_blue "to uninstall speedtest and speedtest-go"
|
||||||
fi
|
fi
|
||||||
|
if ! command -v ping >/dev/null 2>&1; then
|
||||||
|
_green "Installing ping"
|
||||||
|
${PACKAGE_INSTALL[int]} iputils-ping >/dev/null 2>&1
|
||||||
|
${PACKAGE_INSTALL[int]} ping >/dev/null 2>&1
|
||||||
|
fi
|
||||||
if [ "$(uname -s)" = "Darwin" ]; then
|
if [ "$(uname -s)" = "Darwin" ]; then
|
||||||
echo "Detected MacOS. Installing sysbench and fio..."
|
echo "Detected MacOS. Installing sysbench and fio..."
|
||||||
brew install --force sysbench fio dd
|
brew install --force sysbench fio dd
|
||||||
# 有问题,需要修复,root环境不能brew,brew安装完毕后可能路径不在环境变量中
|
# 有问题,需要修复,root环境不能brew,brew安装完毕后可能路径不在环境变量中
|
||||||
|
else
|
||||||
|
if ! grep -q "^net.ipv4.ping_group_range = 0 2147483647$" /etc/sysctl.conf; then
|
||||||
|
echo "net.ipv4.ping_group_range = 0 2147483647" >> /etc/sysctl.conf
|
||||||
|
sysctl -p
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
_green "The environment is ready."
|
_green "The environment is ready."
|
||||||
}
|
}
|
||||||
@@ -318,6 +332,7 @@ show_help() {
|
|||||||
Available commands:
|
Available commands:
|
||||||
|
|
||||||
./goecs.sh env Check and Install package:
|
./goecs.sh env Check and Install package:
|
||||||
|
sudo (Almost all unix-like systems have it.)
|
||||||
tar (Almost all unix-like systems have it.)
|
tar (Almost all unix-like systems have it.)
|
||||||
unzip (Almost all unix-like systems have it.)
|
unzip (Almost all unix-like systems have it.)
|
||||||
dd (Almost all unix-like systems have it.)
|
dd (Almost all unix-like systems have it.)
|
||||||
@@ -325,6 +340,7 @@ Available commands:
|
|||||||
sysbench (Almost all unix-like systems can be installed through the system's package manager.)
|
sysbench (Almost all unix-like systems can be installed through the system's package manager.)
|
||||||
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.)
|
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.)
|
||||||
speedtest (Use the officially provided binaries for more accurate test results.)
|
speedtest (Use the officially provided binaries for more accurate test results.)
|
||||||
|
ping (Use the officially provided binaries for more accurate test results.)
|
||||||
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested.
|
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested.
|
||||||
./goecs.sh install Install goecs command
|
./goecs.sh install Install goecs command
|
||||||
./goecs.sh upgrade Upgrade goecs command
|
./goecs.sh upgrade Upgrade goecs command
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/imroc/req/v3"
|
"github.com/imroc/req/v3"
|
||||||
"github.com/oneclickvirt/UnlockTests/uts"
|
"github.com/oneclickvirt/UnlockTests/uts"
|
||||||
"github.com/oneclickvirt/basics/system"
|
"github.com/oneclickvirt/basics/system"
|
||||||
|
. "github.com/oneclickvirt/defaultset"
|
||||||
"github.com/oneclickvirt/security/network"
|
"github.com/oneclickvirt/security/network"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -44,6 +45,89 @@ func PrintHead(language string, width int, ecsVersion string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckChina(enableLogger bool) bool {
|
||||||
|
if enableLogger {
|
||||||
|
InitLogger()
|
||||||
|
defer Logger.Sync()
|
||||||
|
}
|
||||||
|
var selectChina bool
|
||||||
|
client := req.C()
|
||||||
|
client.SetTimeout(6 * time.Second)
|
||||||
|
client.R().
|
||||||
|
SetRetryCount(2).
|
||||||
|
SetRetryBackoffInterval(1*time.Second, 3*time.Second).
|
||||||
|
SetRetryFixedInterval(2 * time.Second)
|
||||||
|
ipapiURL := "https://ipapi.co/json"
|
||||||
|
cipccURL := "http://cip.cc"
|
||||||
|
ipapiResp, err := client.R().Get(ipapiURL)
|
||||||
|
if err != nil {
|
||||||
|
if enableLogger {
|
||||||
|
Logger.Info("无法获取IP信息:" + err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defer ipapiResp.Body.Close()
|
||||||
|
var ipapiBody string
|
||||||
|
ipapiBody, err = ipapiResp.ToString()
|
||||||
|
if err != nil {
|
||||||
|
if enableLogger {
|
||||||
|
Logger.Info("无法读取IP信息响应:" + err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
isInChina := strings.Contains(ipapiBody, "China")
|
||||||
|
if isInChina {
|
||||||
|
fmt.Println("根据ipapi.co提供的信息,当前IP可能在中国")
|
||||||
|
var input string
|
||||||
|
fmt.Print("是否选用中国专项测试(无流媒体测试,有三网Ping值测试)? ([y]/n) ")
|
||||||
|
fmt.Scanln(&input)
|
||||||
|
switch strings.ToLower(input) {
|
||||||
|
case "yes", "y":
|
||||||
|
fmt.Println("使用中国专项测试")
|
||||||
|
selectChina = true
|
||||||
|
case "no", "n":
|
||||||
|
fmt.Println("不使用中国专项测试")
|
||||||
|
default:
|
||||||
|
fmt.Println("使用中国专项测试")
|
||||||
|
selectChina = true
|
||||||
|
}
|
||||||
|
return selectChina
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cipccResp, err := client.R().Get(cipccURL)
|
||||||
|
if err != nil {
|
||||||
|
if enableLogger {
|
||||||
|
Logger.Info("无法获取IP信息:" + err.Error())
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer cipccResp.Body.Close()
|
||||||
|
cipccBody, err := cipccResp.ToString()
|
||||||
|
if err != nil {
|
||||||
|
if enableLogger {
|
||||||
|
Logger.Info("无法读取IP信息响应:" + err.Error())
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
isInChina := strings.Contains(cipccBody, "中国")
|
||||||
|
if isInChina {
|
||||||
|
fmt.Println("根据cip.cc提供的信息,当前IP可能在中国")
|
||||||
|
var input string
|
||||||
|
fmt.Print("是否选用中国专项测试(无流媒体测试,有三网Ping值测试)? ([y]/n) ")
|
||||||
|
fmt.Scanln(&input)
|
||||||
|
switch strings.ToLower(input) {
|
||||||
|
case "yes", "y":
|
||||||
|
fmt.Println("使用中国专项测试")
|
||||||
|
selectChina = true
|
||||||
|
case "no", "n":
|
||||||
|
fmt.Println("不使用中国专项测试")
|
||||||
|
default:
|
||||||
|
fmt.Println("不使用中国专项测试")
|
||||||
|
selectChina = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectChina
|
||||||
|
}
|
||||||
|
|
||||||
// SecurityCheck 执行安全检查
|
// SecurityCheck 执行安全检查
|
||||||
func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (string, string, string) {
|
func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (string, string, string) {
|
||||||
var wgt sync.WaitGroup
|
var wgt sync.WaitGroup
|
||||||
|
Reference in New Issue
Block a user