Files
2026-07-13 22:56:03 +08:00

362 lines
12 KiB
Bash

#!/usr/bin/env bash
#by spiritlhl
#From https://github.com/spiritLHLS/ecs
#2025.02.12
cd /root >/dev/null 2>&1
myvar=$(pwd)
TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/ipcheck.XXXXXX") || exit 1
SECURITY_CHECK_BIN="${TEMP_DIR}/securityCheck"
PORT_CHECKER_BIN="${TEMP_DIR}/pck"
IP_QUALITY_GOOGLE_FILE="${TEMP_DIR}/ip_quality_google"
IP_QUALITY_SECURITY_FILE="${TEMP_DIR}/ip_quality_security_check"
IP_QUALITY_EMAIL_FILE="${TEMP_DIR}/ip_quality_email_check"
cleanup_temp_dir() {
if [ -n "${TEMP_DIR:-}" ] && [ -d "$TEMP_DIR" ]; then
rm -rf -- "$TEMP_DIR"
fi
}
trap cleanup_temp_dir EXIT
ver="2026.07.13"
changeLog="IP质量测试,由频道 https://t.me/+UHVoo2U4VyA5NTQ1 原创"
en_status=false
shorturl=""
REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "alpine")
RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Alpine")
PACKAGE_UPDATE=("apt -y update" "apt -y update" "yum -y update" "yum -y update" "apk update -f")
PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install" "yum -y install" "apk add -f")
CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')")
rm -f -- sc_result.txt
# 安全的清屏函数
clear_screen() {
if [ -t 1 ]; then
tput clear 2>/dev/null || echo -e "\033[2J\033[H" || clear
fi
}
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "UTF-8|utf8")
SYS="${CMD[0]}"
if [[ -z "$utf8_locale" ]]; then
echo "No UTF-8 locale found"
else
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
echo "Locale set to $utf8_locale"
fi
[[ -n $SYS ]] || exit 1
for ((int = 0; int < ${#REGEX[@]}; int++)); do
if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then
SYSTEM="${RELEASE[int]}"
[[ -n $SYSTEM ]] && break
fi
done
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
PLAIN="\033[0m"
_red() { echo -e "\033[31m\033[01m$*\033[0m"; }
_green() { echo -e "\033[32m\033[01m$*\033[0m"; }
_yellow() { echo -e "\033[33m\033[01m$*\033[0m"; }
_blue() { echo -e "\033[36m\033[01m$*\033[0m"; }
reading() { read -rp "$(_green "$1")" "$2"; }
os=$(uname -s)
arch=$(uname -m)
print_intro() {
echo "-----------------------A Bench Script By spiritlhl-----------------------"
echo " 测评频道: https://t.me/+UHVoo2U4VyA5NTQ1 "
echo "版本:$ver"
echo "更新日志:$changeLog"
}
check_and_cat_file() {
local file="$1"
if [[ -f "$file" ]]; then
if [[ -s "$file" ]] && [[ "$(grep -vE '^\s*$' "$file")" ]]; then
if ! grep -q "error" "$file"; then
cat "$file"
fi
fi
fi
}
format_output() {
local file="$1"
sed -i 's/\x1B\[[0-9;]*[JKmsu]//g' "$file"
sed -i 's/^\[H//' "$file"
if ! grep -q "A Bench Script By spiritlhl" "$file"; then
sed -i '1i\-------------------- A Bench Script By spiritlhl ---------------------' "$file"
fi
}
build_text() {
cd "$myvar" >/dev/null 2>&1
if [ -f "sc_result.txt" ]; then
format_output "sc_result.txt"
awk '/A Bench Script By spiritlhl/{flag=1} flag; /^$/{flag=0}' sc_result.txt >"$TEMP_DIR/sc_result.tmp" && mv "$TEMP_DIR/sc_result.tmp" sc_result.txt
sed -i -e 's/\x1B\[[0-9;]\+[a-zA-Z]//g' sc_result.txt
sed -i -e '/^$/d' sc_result.txt
sed -i 's/\r//' sc_result.txt
# 检查文件大小是否小于 25KB
if [ ! -s sc_result.txt ]; then
echo "The file sc_result.txt is empty and has not been uploaded."
return
fi
file_size=$(wc -c <"sc_result.txt")
if [ "$file_size" -ge 25600 ]; then
echo "Files larger than 25KB (${file_size} bytes) are not uploaded."
return
fi
if [ -s sc_result.txt ]; then
http_short_url=$(curl --ipv4 -sL -m 10 -X POST \
-H "Authorization: $ST" \
-F "file=@${myvar}/sc_result.txt" \
"https://paste.spiritlhl.net/api/UL/upload")
if [ $? -eq 0 ] && [ -n "$http_short_url" ] && echo "$http_short_url" | grep -q "show"; then
file_id=$(echo "$http_short_url" | grep -o '[^/]*$')
shorturl="https://paste.spiritlhl.net/#/show/${file_id}"
else
https_short_url=$(curl --ipv6 -sL -m 10 -X POST \
-H "Authorization: $ST" \
-F "file=@${myvar}/sc_result.txt" \
"https://paste.spiritlhl.net/api/UL/upload")
if [ $? -eq 0 ] && [ -n "$https_short_url" ] && echo "$https_short_url" | grep -q "show"; then
file_id=$(echo "$https_short_url" | grep -o '[^/]*$')
shorturl="https://paste.spiritlhl.net/#/show/${file_id}"
else
shorturl=""
fi
fi
fi
fi
}
check_cdn() {
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL --proto '=https' --proto-redir '=https' "$cdn_url$o_url" --max-time 6 | grep -q "success" >/dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
}
check_cdn_file() {
check_cdn "https://raw.githubusercontent.com/spiritLHLS/ecs/main/back/test"
if [ -n "$cdn_success_url" ]; then
_yellow "CDN available, using CDN"
else
_yellow "No CDN available, using original links"
export cdn_success_url=""
fi
}
pre_download() {
local platform
local machine
case $os in
Linux) platform="linux" ;;
Darwin) platform="darwin" ;;
FreeBSD) platform="freebsd" ;;
*)
echo "Unsupported operating system: $os"
exit 1
;;
esac
case $arch in
"x86_64" | "x86" | "amd64" | "x64") machine="amd64" ;;
"i386" | "i686") machine="386" ;;
"armv7l" | "armv8" | "armv8l" | "aarch64") machine="arm64" ;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
if ! curl --fail --location --proto '=https' --proto-redir '=https' -o "$SECURITY_CHECK_BIN.download" "${cdn_success_url}https://github.com/oneclickvirt/securityCheck/releases/download/output/securityCheck-${platform}-${machine}"; then
rm -f "$SECURITY_CHECK_BIN.download"
return 1
fi
mv "$SECURITY_CHECK_BIN.download" "$SECURITY_CHECK_BIN"
if ! curl --fail --location --proto '=https' --proto-redir '=https' -o "$PORT_CHECKER_BIN.download" "${cdn_success_url}https://github.com/oneclickvirt/portchecker/releases/download/output/portchecker-${platform}-${machine}"; then
rm -f "$PORT_CHECKER_BIN.download"
return 1
fi
mv "$PORT_CHECKER_BIN.download" "$PORT_CHECKER_BIN"
}
translate_status() {
if [[ "$1" == "false" ]]; then
echo "No"
elif [[ "$1" == "true" ]]; then
echo "Yes"
else
echo "$1"
fi
}
google() {
local curl_result=$(curl -sL -m 10 "https://www.google.com/search?q=www.spiritysdx.top" -H "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0")
rm -f "$IP_QUALITY_GOOGLE_FILE"
if [ "$en_status" = true ]; then
if echo "$curl_result" | grep -q "二叉树的博客"; then
echo "Google search feasibility: YES" >>"$IP_QUALITY_GOOGLE_FILE"
else
echo "Google search feasibility: NO" >>"$IP_QUALITY_GOOGLE_FILE"
fi
else
if echo "$curl_result" | grep -q "二叉树的博客"; then
echo "Google搜索可行性:YES" >>"$IP_QUALITY_GOOGLE_FILE"
else
echo "Google搜索可行性:NO" >>"$IP_QUALITY_GOOGLE_FILE"
fi
fi
}
security_check() {
local language=$1
cd "$myvar" >/dev/null 2>&1
if [ -f "$SECURITY_CHECK_BIN" ]; then
chmod 700 "$SECURITY_CHECK_BIN"
"$SECURITY_CHECK_BIN" -l "$language" -e yes | sed '1d' >>"$IP_QUALITY_SECURITY_FILE"
fi
}
email_check() {
cd "$myvar" >/dev/null 2>&1
if [ -f "$PORT_CHECKER_BIN" ]; then
chmod 700 "$PORT_CHECKER_BIN"
"$PORT_CHECKER_BIN" | sed '1d' >>"$IP_QUALITY_EMAIL_FILE"
fi
}
ST="OvwKx5qgJtf7PZgCKbtyojSU.MTcwMTUxNzY1MTgwMw"
next() {
echo -en "\r"
[ "${Var_OSRelease}" = "freebsd" ] && printf "%-72s\n" "-" | tr ' ' '-' && return
printf "%-72s\n" "-" | sed 's/\s/-/g'
}
print_end_time() {
end_time=$(date +%s)
time=$((${end_time} - ${start_time}))
if [ ${time} -gt 60 ]; then
min=$(expr $time / 60)
sec=$(expr $time % 60)
echo " 总共花费 : ${min}${sec} 秒"
else
echo " 总共花费 : ${time} 秒"
fi
date_time=$(date +%Y-%m-%d" "%H:%M:%S)
echo " 时间 : $date_time"
}
ipcheck() {
{
google
if [[ $? -ne 0 ]]; then
echo "Google检测执行失败" >>"$IP_QUALITY_GOOGLE_FILE"
fi
} &
if [ "$en_status" = true ]; then
{
security_check "en"
if [[ $? -ne 0 ]]; then
echo "Security check failed" >>"$IP_QUALITY_SECURITY_FILE"
fi
} &
else
{
security_check "zh"
if [[ $? -ne 0 ]]; then
echo "安全检查执行失败" >>"$IP_QUALITY_SECURITY_FILE"
fi
} &
fi
{
email_check
if [[ $? -ne 0 ]]; then
echo "邮件端口检测执行失败" >>"$IP_QUALITY_EMAIL_FILE"
fi
} &
# 等待所有后台任务完成
wait
# 检查并显示结果
local has_output=false
if [ -f "$IP_QUALITY_SECURITY_FILE" ]; then
check_and_cat_file "$IP_QUALITY_SECURITY_FILE"
has_output=true
fi
if [ -f "$IP_QUALITY_GOOGLE_FILE" ]; then
check_and_cat_file "$IP_QUALITY_GOOGLE_FILE"
has_output=true
fi
if [ "$en_status" = true ]; then
echo -e "---------Email-Port-Detection--Base-On-oneclickvirt/portchecker----------"
else
echo -e "----------邮件端口检测--基于oneclickvirt/portchecker开源----------"
fi
if [ -f "$IP_QUALITY_EMAIL_FILE" ]; then
check_and_cat_file "$IP_QUALITY_EMAIL_FILE"
has_output=true
fi
# 如果没有任何输出,输出错误信息
if [ "$has_output" = false ]; then
echo "警告: 未能获取到任何检测结果"
fi
# 清理临时文件
rm -f "$IP_QUALITY_SECURITY_FILE" "$IP_QUALITY_GOOGLE_FILE" "$IP_QUALITY_EMAIL_FILE"
}
main() {
cdn_urls=("https://cdn0.spiritlhl.top/" "https://cdn.spiritlhl.net/")
check_cdn_file
pre_download || exit 1
chmod 700 "$SECURITY_CHECK_BIN" 2>/dev/null
# 清屏
clear_screen
start_time=$(date +%s)
print_intro
_yellow "数据仅作参考,不代表100%准确,IP类型如果不一致请手动查询多个数据库比对"
echo -e "----------IP质量检测--基于oneclickvirt/securityCheck使用----------"
# 执行检测并保存到临时文件
temp_output=$(mktemp "$TEMP_DIR/output.XXXXXX")
ipcheck | tee "$temp_output"
# 检查输出
if [ ! -s "$temp_output" ]; then
echo "警告: 首次检测结果为空,正在重试..."
sleep 2
ipcheck | tee "$temp_output"
fi
rm -f "$temp_output"
next
print_end_time
next
}
: >sc_result.txt
main | tee -i sc_result.txt
build_text
if [ -n "$shorturl" ]; then
_green " 短链:"
_blue " $shorturl"
fi
cleanup_temp_dir