From 733c5ef5bb6454fbabbd0c5440c1c8af3ac8d85c Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 01:42:12 +0800 Subject: [PATCH 01/13] update bench --- Cnbench.sh | 614 ++++++++++++++++++++++++++++++++++++++++++++++ Nlbench.sh | 33 ++- README.md | 17 +- server/bench.html | 216 ++++++++++++++++ server/index.php | 61 +++++ version.sh | 1 + 6 files changed, 926 insertions(+), 16 deletions(-) create mode 100644 Cnbench.sh create mode 100644 server/bench.html create mode 100644 server/index.php diff --git a/Cnbench.sh b/Cnbench.sh new file mode 100644 index 0000000..20b2c94 --- /dev/null +++ b/Cnbench.sh @@ -0,0 +1,614 @@ +#!/bin/bash + +# 定义版本 +CURRENT_VERSION="2025-01-21 v1.2.7" # 最新版本号 +SCRIPT_URL="https://ghfast.top/https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/Nlbench.sh" +VERSION_URL="https://ghfast.top/https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/version.sh" +CLOUD_SERVICE_BASE="https://bench.nodeloc.cc/" + +# 定义颜色 +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;36m' +NC='\033[0m' # No Color + +# 定义渐变颜色数组 +colors=( + '\033[38;2;0;255;0m' # 绿色 + '\033[38;2;64;255;0m' + '\033[38;2;128;255;0m' + '\033[38;2;192;255;0m' + '\033[38;2;255;255;0m' # 黄色 +) + +# 更新脚本 +update_scripts() { + echo -e "${BLUE}┌─────────────────────────────────────────┐${NC}" + echo -e "${BLUE}│ NodeLoc VPS 测试脚本 │${NC}" + echo -e "${BLUE}│ 版本检查 │${NC}" + echo -e "${BLUE}└─────────────────────────────────────────┘${NC}" + + REMOTE_VERSION=$(curl -s $VERSION_URL | tail -n 1 | grep -oP '(?<=#\s)[\d-]+\sv[\d.]+(?=\s-)') + if [ -z "$REMOTE_VERSION" ]; then + echo -e "${RED}✖ 无法获取远程版本信息。请检查您的网络连接。${NC}" + return 1 + fi + + echo -e "${BLUE}┌─────────────────────────────────────────┐${NC}" + echo -e "${BLUE}│ 版本历史 │${NC}" + echo -e "${BLUE}├─────────────────────────────────────────┤${NC}" + echo -e "${YELLOW} 当前版本: ${GREEN}$CURRENT_VERSION${NC}" + echo -e "${BLUE}├─────────────────────────────────────────┤${NC}" + echo -e "${YELLOW} 版本历史:${NC}" + curl -s $VERSION_URL | grep -oP '(?<=#\s)[\d-]+\sv[\d.]+(?=\s-)' | + while read version; do + if [ "$version" = "$CURRENT_VERSION" ]; then + echo -e " ${GREEN}▶ $version ${NC}(当前版本)" + else + echo -e " $version" + fi + done + echo -e "${BLUE}└─────────────────────────────────────────┘${NC}" + + if [ "$REMOTE_VERSION" != "$CURRENT_VERSION" ]; then + echo -e "\n${YELLOW}发现新版本: ${GREEN}$REMOTE_VERSION${NC}" + echo -e "${BLUE}正在更新...${NC}" + + if curl -s -o /tmp/NLbench.sh $SCRIPT_URL; then + NEW_VERSION=$(grep '^CURRENT_VERSION=' /tmp/NLbench.sh | cut -d'"' -f2) + if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then + sed -i "s/^CURRENT_VERSION=.*/CURRENT_VERSION=\"$NEW_VERSION\"/" "$0" + + if mv /tmp/NLbench.sh "$0"; then + chmod +x "$0" + echo -e "${GREEN}┌─────────────────────────────────────────┐${NC}" + echo -e "${GREEN}│ 脚本更新成功! │${NC}" + echo -e "${GREEN}└─────────────────────────────────────────┘${NC}" + echo -e "${YELLOW}新版本: ${GREEN}$NEW_VERSION${NC}" + echo -e "${YELLOW}正在重新启动脚本以应用更新...${NC}" + sleep 3 + exec bash "$0" + else + echo -e "${RED}✖ 无法替换脚本文件。请检查权限。${NC}" + return 1 + fi + else + echo -e "${GREEN}✔ 脚本已是最新版本。${NC}" + fi + else + echo -e "${RED}✖ 下载新版本失败。请稍后重试。${NC}" + return 1 + fi + else + echo -e "\n${GREEN}✔ 脚本已是最新版本。${NC}" + fi + + echo -e "${BLUE}┌─────────────────────────────────────────┐${NC}" + echo -e "${BLUE}│ 更新检查完成 │${NC}" + echo -e "${BLUE}└─────────────────────────────────────────┘${NC}" +} + +# 检查 root 权限并获取 sudo 权限 +check_root() { + if [ "$(id -u)" != "0" ]; then + echo "此脚本需要 root 权限运行。" + if ! sudo -v; then + echo "无法获取 sudo 权限,退出脚本。" + exit 1 + fi + echo "已获取 sudo 权限。" + fi +} + +# 检测操作系统 +detect_os() { + if [ -f /etc/os-release ]; then + . /etc/os-release + os_type=$ID + elif type lsb_release >/dev/null 2>&1; then + os_type=$(lsb_release -si) + elif [ -f /etc/lsb-release ]; then + . /etc/lsb-release + os_type=$DISTRIB_ID + elif [ -f /etc/debian_version ]; then + os_type="debian" + elif [ -f /etc/fedora-release ]; then + os_type="fedora" + elif [ -f /etc/centos-release ]; then + os_type="centos" + else + os_type=$(uname -s) + fi + os_type=$(echo $os_type | tr '[:upper:]' '[:lower:]') + echo "检测到的操作系统: $os_type" +} + +# 更新系统 +update_system() { + detect_os + if [ $? -ne 0 ]; then + echo -e "${RED}无法检测操作系统。${NC}" + return 1 + fi + case "${os_type,,}" in + ubuntu|debian|linuxmint|elementary|pop) + update_cmd="apt-get update" + upgrade_cmd="apt-get upgrade -y" + clean_cmd="apt-get autoremove -y" + ;; + centos|rhel|fedora|rocky|almalinux|openeuler) + if command -v dnf &>/dev/null; then + update_cmd="dnf check-update" + upgrade_cmd="dnf upgrade -y" + clean_cmd="dnf autoremove -y" + else + update_cmd="yum check-update" + upgrade_cmd="yum upgrade -y" + clean_cmd="yum autoremove -y" + fi + ;; + opensuse*|sles) + update_cmd="zypper refresh" + upgrade_cmd="zypper dup -y" + clean_cmd="zypper clean -a" + ;; + arch|manjaro) + update_cmd="pacman -Sy" + upgrade_cmd="pacman -Syu --noconfirm" + clean_cmd="pacman -Sc --noconfirm" + ;; + alpine) + update_cmd="apk update" + upgrade_cmd="apk upgrade" + clean_cmd="apk cache clean" + ;; + gentoo) + update_cmd="emerge --sync" + upgrade_cmd="emerge -uDN @world" + clean_cmd="emerge --depclean" + ;; + cloudlinux) + update_cmd="yum check-update" + upgrade_cmd="yum upgrade -y" + clean_cmd="yum clean all" + ;; + *) + echo -e "${RED}不支持的 Linux 发行版: $os_type${NC}" + return 1 + ;; + esac + + echo -e "${YELLOW}正在更新系统...${NC}" + sudo $update_cmd + if [ $? -eq 0 ]; then + sudo $upgrade_cmd + if [ $? -eq 0 ]; then + echo -e "${GREEN}系统更新完成。${NC}" + echo -e "${YELLOW}正在清理系统...${NC}" + sudo $clean_cmd + echo -e "${GREEN}系统清理完成。${NC}" + # 检查是否需要重启 + if [ -f /var/run/reboot-required ]; then + echo -e "${YELLOW}系统更新需要重启才能完成。请在方便时重启系统。${NC}" + fi + return 0 + fi + fi + echo -e "${RED}系统更新失败。${NC}" + return 1 +} + +# 定义支持的操作系统类型 +SUPPORTED_OS=("ubuntu" "debian" "linuxmint" "elementary" "pop" "centos" "rhel" "fedora" "rocky" "almalinux" "openeuler" "opensuse" "sles" "arch" "manjaro" "alpine" "gentoo" "cloudlinux") + +# 安装依赖 +install_dependencies() { + echo -e "${YELLOW}正在检查并安装必要的依赖项...${NC}" + + # 确保 os_type 已定义 + if [ -z "$os_type" ]; then + detect_os + fi + + # 更新系统 + update_system || echo -e "${RED}系统更新失败。继续安装依赖项。${NC}" + + # 安装依赖 + local dependencies=("curl" "wget" "iperf3" "bc") + + # 检查是否为支持的操作系统 + if [[ ! " ${SUPPORTED_OS[@]} " =~ " ${os_type} " ]]; then + echo -e "${RED}不支持的操作系统: $os_type${NC}" + return 1 + fi + + case "${os_type,,}" in + gentoo) + install_cmd="emerge" + for dep in "${dependencies[@]}"; do + if ! emerge -p $dep &>/dev/null; then + echo -e "${YELLOW}正在安装 $dep...${NC}" + if ! sudo $install_cmd $dep; then + echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" + fi + else + echo -e "${GREEN}$dep 已安装。${NC}" + fi + done + ;; + alpine) + install_cmd="apk add" + for dep in "${dependencies[@]}"; do + if ! command -v "$dep" &> /dev/null; then + echo -e "${YELLOW}正在安装 $dep...${NC}" + if ! sudo $install_cmd "$dep"; then + echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" + fi + else + echo -e "${GREEN}$dep 已安装。${NC}" + fi + done + ;; + *) + for dep in "${dependencies[@]}"; do + if ! command -v "$dep" &> /dev/null; then + echo -e "${YELLOW}正在安装 $dep...${NC}" + if ! sudo $install_cmd "$dep"; then + echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" + fi + else + echo -e "${GREEN}$dep 已安装。${NC}" + fi + done + ;; + esac + + echo -e "${GREEN}依赖项检查和安装完成。${NC}" + clear +} + +# 获取IP地址和ISP信息 +ip_address_and_isp() { + ipv4_address=$(curl -s --max-time 5 ipv4.ip.sb) + if [ -z "$ipv4_address" ]; then + ipv4_address=$(ip -4 addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v '127.0.0.1' | head -n1) + fi + + ipv6_address=$(curl -s --max-time 5 ipv6.ip.sb) + if [ -z "$ipv6_address" ]; then + ipv6_address=$(ip -6 addr show | grep -oP '(?<=inet6\s)[\da-f:]+' | grep -v '^::1' | grep -v '^fe80' | head -n1) + fi + + # 获取ISP信息 + isp_info=$(curl -s ipinfo.io/org) + + # 检查是否为WARP或Cloudflare + is_warp=false + if echo "$isp_info" | grep -iq "cloudflare\|warp\|1.1.1.1"; then + is_warp=true + fi + + # 判断使用IPv6还是IPv4 + use_ipv6=false + if [ "$is_warp" = true ] || [ -z "$ipv4_address" ]; then + use_ipv6=true + fi + + echo "IPv4: $ipv4_address" + echo "IPv6: $ipv6_address" + echo "ISP: $isp_info" + echo "Is WARP: $is_warp" + echo "Use IPv6: $use_ipv6" +} + +# 检测VPS地理位置 +detect_region() { + local country + country=$(curl -s ipinfo.io/country) + case $country in + "TW") echo "1" ;; # 台湾 + "HK") echo "2" ;; # 香港 + "JP") echo "3" ;; # 日本 + "US" | "CA") echo "4" ;; # 北美 + "BR" | "AR" | "CL") echo "5" ;; # 南美 + "GB" | "DE" | "FR" | "NL" | "SE" | "NO" | "FI" | "DK" | "IT" | "ES" | "CH" | "AT" | "BE" | "IE" | "PT" | "GR" | "PL" | "CZ" | "HU" | "RO" | "BG" | "HR" | "SI" | "SK" | "LT" | "LV" | "EE") echo "6" ;; # 欧洲 + "AU" | "NZ") echo "7" ;; # 大洋洲 + "KR") echo "8" ;; # 韩国 + "SG" | "MY" | "TH" | "ID" | "PH" | "VN") echo "9" ;; # 东南亚 + "IN") echo "10" ;; # 印度 + "ZA" | "NG" | "EG" | "KE" | "MA" | "TN" | "GH" | "CI" | "SN" | "UG" | "ET" | "MZ" | "ZM" | "ZW" | "BW" | "MW" | "NA" | "RW" | "SD" | "DJ" | "CM" | "AO") echo "11" ;; # 非洲 + *) echo "0" ;; # 跨国平台 + esac +} + +# 统计使用次数 +sum_run_times() { + local COUNT=$(wget --no-check-certificate -qO- --tries=2 --timeout=2 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fnodeloc%2Fnodeloc_vps_test%2Fblob%2Fmain%2FNlbench.sh" 2>&1 | grep -m1 -oE "[0-9]+[ ]+/[ ]+[0-9]+") + if [[ -n "$COUNT" ]]; then + daily_count=$(cut -d " " -f1 <<< "$COUNT") + total_count=$(cut -d " " -f3 <<< "$COUNT") + else + echo "Failed to fetch usage counts." + daily_count=0 + total_count=0 + fi +} + +# 执行单个脚本并输出结果到文件 +run_script() { + local script_number=$1 + local output_file=$2 + local temp_file=$(mktemp) + # 调用ip_address_and_isp函数获取IP地址和ISP信息 + ip_address_and_isp + case $script_number in + # YABS + 1) + echo -e "运行${YELLOW}YABS...${NC}" + curl -sL yabs.sh | bash -s -- -i -5 | tee "$temp_file" + sed -i 's/\x1B\[[0-9;]*[JKmsu]//g' "$temp_file" + sed -i 's/\.\.\./\.\.\.\n/g' "$temp_file" + sed -i '/\.\.\./d' "$temp_file" + sed -i '/^\s*$/d' "$temp_file" + cp "$temp_file" "${output_file}_yabs" + ;; + # IP质量 + 2) + echo -e "运行${YELLOW}IP质量测试...${NC}" + echo y | bash <(curl -Ls IP.Check.Place) | tee "$temp_file" + sed -i 's/\x1B\[[0-9;]*[JKmsu]//g' "$temp_file" + sed -i -r 's/(⠋|⠙|⠹|⠸|⠼|⠴|⠦|⠧|⠇|⠏)/\n/g' "$temp_file" + sed -i -r '/正在检测/d' "$temp_file" + sed -i -n '/########################################################################/,${s/^.*\(########################################################################\)/\1/;p}' "$temp_file" + sed -i '/^$/d' "$temp_file" + cp "$temp_file" "${output_file}_ip_quality" + ;; + # 流媒体解锁 + 3) + echo -e "运行${YELLOW}流媒体解锁测试...${NC}" + local region=$(detect_region) + bash <(curl -L -s media.ispvps.com) <<< "$region" | tee "$temp_file" + sed -i 's/\x1B\[[0-9;]*[JKmsu]//g' "$temp_file" + sed -i -n '/流媒体平台及游戏区域限制测试/,$p' "$temp_file" + sed -i '1d' "$temp_file" + sed -i '/^$/d' "$temp_file" + cp "$temp_file" "${output_file}_streaming" + ;; + # 响应测试 + 4) + echo -e "运行${YELLOW}响应测试...${NC}" + bash <(curl -sL https://nodebench.mereith.com/scripts/curltime.sh) | tee "$temp_file" + sed -i 's/\x1B\[[0-9;]*[JKmsu]//g' "$temp_file" + cp "$temp_file" "${output_file}_response" + ;; + # 多线程测速 + 5) + echo -e "运行${YELLOW}多线程测速...${NC}" + if [ "$use_ipv6" = true ]; then + echo "使用IPv6测试选项" + bash <(curl -sL https://ghfast.top/https://raw.githubusercontent.com/i-abc/Speedtest/main/speedtest.sh) <<< "3" | tee "$temp_file" + else + echo "使用IPv4测试选项" + bash <(curl -sL https://ghfast.top/https://raw.githubusercontent.com/i-abc/Speedtest/main/speedtest.sh) <<< "1" | tee "$temp_file" + fi + sed -r -i 's/\x1B\[[0-9;]*[JKmsu]//g' "$temp_file" + sed -i -r '1,/序号\:/d' "$temp_file" + sed -i -r 's/(⠋|⠙|⠹|⠸|⠼|⠴|⠦|⠧|⠇|⠏)/\n/g' "$temp_file" + sed -i -r '/测试进行中/d' "$temp_file" + sed -i '/^$/d' "$temp_file" + cp "$temp_file" "${output_file}_multi_thread" + ;; + # 单线程测速 + 6) + echo -e "运行${YELLOW}单线程测速...${NC}" + if [ "$use_ipv6" = true ]; then + echo "使用IPv6测试选项" + bash <(curl -sL https://ghfast.top/https://raw.githubusercontent.com/i-abc/Speedtest/main/speedtest.sh) <<< "17" | tee "$temp_file" + else + echo "使用IPv4测试选项" + bash <(curl -sL https://ghfast.top/https://raw.githubusercontent.com/i-abc/Speedtest/main/speedtest.sh) <<< "2" | tee "$temp_file" + fi + sed -r -i 's/\x1B\[[0-9;]*[JKmsu]//g' "$temp_file" + sed -i -r '1,/序号\:/d' "$temp_file" + sed -i -r 's/(⠋|⠙|⠹|⠸|⠼|⠴|⠦|⠧|⠇|⠏)/\n/g' "$temp_file" + sed -i -r '/测试进行中/d' "$temp_file" + sed -i '/^$/d' "$temp_file" + cp "$temp_file" "${output_file}_single_thread" + ;; + # 回程路由 + 7) + echo -e "运行${YELLOW}回程路由测试...${NC}" + if [ "$use_ipv6" = true ]; then + echo "使用IPv6测试选项" + wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "4" | tee "$temp_file" + else + echo "使用IPv4测试选项" + wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "1" | tee "$temp_file" + fi + sed -i -e 's/\x1B\[[0-9;]*[JKmsu]//g' -e '/No:1\/9 Traceroute to/,$!d' -e '/测试项/,+9d' -e '/信息/d' -e '/^\s*$/d' "$temp_file" + cp "$temp_file" "${output_file}_route" + ;; + esac + rm "$temp_file" + echo -e "${GREEN}测试完成。${NC}" +} + +# 生成最终的 Markdown 输出 +generate_markdown_output() { + local base_output_file=$1 + local temp_output_file="${base_output_file}.md" + local sections=("YABS" "IP质量" "流媒体" "响应" "多线程测速" "单线程测速" "回程路由") + local file_suffixes=("yabs" "ip_quality" "streaming" "response" "multi_thread" "single_thread" "route") + local empty_tabs=("去程路由" "Ping.pe" "哪吒 ICMP" "其他") + + # 修改这里,添加 UTF-8 编码设置 + echo "[tabs]" | iconv -f UTF-8 -t UTF-8//IGNORE > "$temp_output_file" + + # 输出有内容的标签 + for i in "${!sections[@]}"; do + section="${sections[$i]}" + suffix="${file_suffixes[$i]}" + if [ -f "${base_output_file}_${suffix}" ]; then + echo "[tab=\"$section\"]" | iconv -f UTF-8 -t UTF-8//IGNORE >> "$temp_output_file" + echo "\`\`\`" >> "$temp_output_file" + cat "${base_output_file}_${suffix}" | iconv -f UTF-8 -t UTF-8//IGNORE >> "$temp_output_file" + echo "\`\`\`" >> "$temp_output_file" + echo "[/tab]" >> "$temp_output_file" + rm "${base_output_file}_${suffix}" + fi + done + + # 添加保留的空白标签 + for tab in "${empty_tabs[@]}"; do + echo "[tab=\"$tab\"]" >> "$temp_output_file" + echo "[/tab]" >> "$temp_output_file" + done + + echo "[/tabs]" >> "$temp_output_file" + + + # 上传文件 获取回调 + local plain_uploaded_file=$(cat ${temp_output_file}|curl -s -X POST --data-binary @- ${CLOUD_SERVICE_BASE}); + local plain_uploaded_file_filename=$(echo "$plain_uploaded_file" | grep -oP "$CLOUD_SERVICE_BASE\K.*") + + + if [ $plain_uploaded_file ]; then + echo -e "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}\r\nPlain $plain_uploaded_file" > "$plain_uploaded_file_filename.url" + + echo "测试结果已上传,您可以在以下链接查看:" + echo "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}" + echo "Plain txt $plain_uploaded_file" + echo "结果链接已保存到 $plain_uploaded_file_filename.url" + else + echo "上传失败。结果已保存在本地文件 $temp_output_file" + fi + + rm "$temp_output_file" + read -p "按回车键继续..." + clear +} + +# 执行全部脚本 +run_all_scripts() { + local base_output_file="NLvps_results_$(date +%Y%m%d_%H%M%S)" + echo "开始执行全部测试脚本..." + for i in {1..10}; do + run_script $i "$base_output_file" + done + generate_markdown_output "$base_output_file" + clear +} + +# 执行选定的脚本 +run_selected_scripts() { + clear + local base_output_file="NLvps_results_$(date +%Y%m%d_%H%M%S)" + echo -e "${YELLOW}Nodeloc VPS 自动测试脚本 $VERSION${NC}" + echo "1. Yabs" + echo "2. IP质量" + echo "3. 流媒体解锁" + echo "4. 响应测试" + echo "5. 多线程测试" + echo "6. 单线程测试" + echo "7. 回程路由" + echo "0. 返回" + + while true; do + read -p "请输入要执行的脚本编号(用英文逗号分隔,例如:1,2,3):" script_numbers + if [[ "$script_numbers" =~ ^(0|10|[1-7])(,(0|10|[1-7]))*$ ]]; then + break + else + echo -e "${RED}无效输入,请输入0-7之间的数字,用英文逗号分隔。${NC}" + fi + done + + IFS=',' read -ra selected_scripts <<< "$script_numbers" + echo "开始执行选定的测试脚本..." + if [ "$script_numbers" == "0" ]; then + clear + show_welcome + else + for number in "${selected_scripts[@]}"; do + clear + run_script "$number" "$base_output_file" + done + generate_markdown_output "$base_output_file" + fi +} + +# 主菜单 +main_menu() { + echo -e "${GREEN}测试项目:${NC}Yabs,IP质量,流媒体解锁,响应测试,多线程测试,单线程测试,回程路由。" + echo -e "${YELLOW}1. 执行所有测试脚本${NC}" + echo -e "${YELLOW}2. 选择特定测试脚本${NC}" + echo -e "${YELLOW}0. 退出${NC}" + read -p "请选择操作 [0-2]: " choice + + case $choice in + 1) + run_all_scripts + ;; + 2) + run_selected_scripts + ;; + 0) + echo -e "${RED}感谢使用NodeLoc聚合测试脚本,已退出脚本,期待你的下次使用!${NC}" + exit 0 + ;; + *) + echo -e "${RED}无效选择,请重新输入。${NC}" + sleep 3s + clear + show_welcome + ;; + esac +} + +# 输出欢迎信息 +show_welcome() { + echo "" + echo -e "${RED}---------------------------------By'Jensfrank---------------------------------${NC}" + echo "" + echo -e "${GREEN}Nodeloc聚合测试脚本 $CURRENT_VERSION ${NC}" + echo -e "${GREEN}GitHub地址: https://github.com/nodeloc/nodeloc_vps_test${NC}" + echo -e "${GREEN}Nodeloc社区: https://www.nodeloc.com/${NC}" + echo "" + echo -e "${colors[0]} _ _ ___ ____ _____ _ ___ ____ __ ______ ____ ${NC}" + echo -e "${colors[1]} | \ | |/ _ \| _ \| ____| | / _ \ / ___| \ \ / / _ \/ ___| ${NC}" + echo -e "${colors[2]} | \| | | | | | | | _| | | | | | | | \ \ / /| |_) \___ \ ${NC}" + echo -e "${colors[3]} | |\ | |_| | |_| | |___| |__| |_| | |___ \ V / | __/ ___) |${NC}" + echo -e "${colors[4]} |_| \_|\___/|____/|_____|_____\___/ \____| \_/ |_| |____/ ${NC}" + echo "" + echo "支持Ubuntu/Debian" + echo "" + echo -e "今日运行次数: ${RED}$daily_count${NC} 次,累计运行次数: ${RED}$total_count${NC} 次" + echo "" + echo -e "${RED}---------------------------------By'Jensfrank---------------------------------${NC}" + echo "" +} + +# 主函数 +main() { + + # 更新脚本 + update_scripts + + # 检查是不是root用户 + check_root + + # 检查并安装依赖 + install_dependencies + + # 调用函数获取统计数据 + sum_run_times + + # 主循环 + while true; do + show_welcome + main_menu + done +} + +# 运行主函数 +main diff --git a/Nlbench.sh b/Nlbench.sh index 3b36af3..8e1e18a 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -1,9 +1,9 @@ #!/bin/bash # 定义版本 -CURRENT_VERSION="2024-09-21 v1.2.6" # 最新版本号 -SCRIPT_URL="https://raw.githubusercontent.com/everett7623/nodeloc_vps_test/main/Nlbench.sh" -VERSION_URL="https://raw.githubusercontent.com/everett7623/nodeloc_vps_test/main/version.sh" +CURRENT_VERSION="2025-01-21 v1.2.7" # 最新版本号 +SCRIPT_URL="https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/Nlbench.sh" +VERSION_URL="https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/version.sh" CLOUD_SERVICE_BASE="https://bench.nodeloc.cc/" # 定义颜色 @@ -324,7 +324,7 @@ detect_region() { # 统计使用次数 sum_run_times() { - local COUNT=$(wget --no-check-certificate -qO- --tries=2 --timeout=2 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Feverett7623%2Fnodeloc_vps_test%2Fblob%2Fmain%2FNlbench.sh" 2>&1 | grep -m1 -oE "[0-9]+[ ]+/[ ]+[0-9]+") + local COUNT=$(wget --no-check-certificate -qO- --tries=2 --timeout=2 "https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fnodeloc%2Fnodeloc_vps_test%2Fblob%2Fmain%2FNlbench.sh" 2>&1 | grep -m1 -oE "[0-9]+[ ]+/[ ]+[0-9]+") if [[ -n "$COUNT" ]]; then daily_count=$(cut -d " " -f1 <<< "$COUNT") total_count=$(cut -d " " -f3 <<< "$COUNT") @@ -469,14 +469,14 @@ generate_markdown_output() { # 上传文件 获取回调 - local plain_uploaded_file=$(cat ${temp_output_file}|curl -s -X POST --data-binary @- ${CLOUD_SERVICE_BASE}test.php); + local plain_uploaded_file=$(cat ${temp_output_file}|curl -s -X POST --data-binary @- ${CLOUD_SERVICE_BASE}); local plain_uploaded_file_filename=$(echo "$plain_uploaded_file" | grep -oP "$CLOUD_SERVICE_BASE\K.*") if [ $plain_uploaded_file ]; then echo -e "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}\r\nPlain $plain_uploaded_file" > "$plain_uploaded_file_filename.url" - echo "测试结果已上传。您可以在以下链接查看:" + echo "测试结果已上传,您可以在以下链接查看:" echo "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}" echo "Plain $plain_uploaded_file" echo "结果链接已保存到 $plain_uploaded_file_filename.url" @@ -543,8 +543,20 @@ main_menu() { echo -e "${YELLOW}1. 执行所有测试脚本${NC}" echo -e "${YELLOW}2. 选择特定测试脚本${NC}" echo -e "${YELLOW}0. 退出${NC}" + + # 提示输入并读取 read -p "请选择操作 [0-2]: " choice + # 确保输入非空 + if [[ -z "$choice" ]]; then + echo -e "${RED}输入为空,请重新输入。${NC}" + sleep 2s + clear + main_menu + return + fi + + # 检查输入是否合法 case $choice in 1) run_all_scripts @@ -558,21 +570,22 @@ main_menu() { ;; *) echo -e "${RED}无效选择,请重新输入。${NC}" - sleep 3s + sleep 2s clear - show_welcome + main_menu ;; esac } + # 输出欢迎信息 show_welcome() { echo "" echo -e "${RED}---------------------------------By'Jensfrank---------------------------------${NC}" echo "" echo -e "${GREEN}Nodeloc聚合测试脚本 $CURRENT_VERSION ${NC}" - echo -e "${GREEN}GitHub地址: https://github.com/everett7623/nodeloc_vps_test${NC}" - echo -e "${GREEN}VPS选购: https://www.nodeloc.com/vps${NC}" + echo -e "${GREEN}GitHub地址: https://github.com/nodeloc/nodeloc_vps_test${NC}" + echo -e "${GREEN}Nodeloc社区: https://www.nodeloc.com/${NC}" echo "" echo -e "${colors[0]} _ _ ___ ____ _____ _ ___ ____ __ ______ ____ ${NC}" echo -e "${colors[1]} | \ | |/ _ \| _ \| ____| | / _ \ / ___| \ \ / / _ \/ ___| ${NC}" diff --git a/README.md b/README.md index e7be760..2454a1e 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ 这是NodeLoc提供给各位用户的主机聚合测评脚本,可一键自动对主机进行Yabs、融合怪、IP质量、流媒体解锁,三网测速,回程路由等测评,测评结束后会生成一个txt文件,可在线自行复制内容 发到NodeLoc论坛。 -**版本:** 2024-09-08 v1.2.4 +**版本:** 2025-01-21 v1.2.7 -**Github地址:** https://github.com/everett7623/nodeloc_vps_test +**Github地址:** https://github.com/nodeloc/nodeloc_vps_test **VPS 选购:** [NodeLoc VPS](https://www.nodeloc.com/vps) @@ -13,13 +13,18 @@ **支持CentOS/Debian/Ubuntu/Deepin** -CentOS ```bash -yum install wget&&wget -O Nlbench.sh https://raw.githubusercontent.com/everett7623/nodeloc_vps_test/main/Nlbench.sh && chmod +x Nlbench.sh && ./Nlbench.sh +curl -o Nlbench.sh https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/Nlbench.sh && chmod +x Nlbench.sh && ./Nlbench.sh ``` -Debian/Ubuntu/Deepin +** 短链接 ```bash -wget -O Nlbench.sh https://raw.githubusercontent.com/everett7623/nodeloc_vps_test/main/Nlbench.sh && chmod +x Nlbench.sh && ./Nlbench.sh +curl -sSL abc.sd | bash +``` + +** 中国大陆 + +```bash +curl -o Nlbench.sh https://ghfast.top/https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/Cnbench.sh && chmod +x Nlbench.sh && ./Nlbench.sh ``` ### 效果图 diff --git a/server/bench.html b/server/bench.html new file mode 100644 index 0000000..e6eed88 --- /dev/null +++ b/server/bench.html @@ -0,0 +1,216 @@ + + + + + + Nodeloc Bench Result + + + + + +
Loading...
+ + + + + + + + + + + + + + + + + diff --git a/server/index.php b/server/index.php new file mode 100644 index 0000000..c521dfc --- /dev/null +++ b/server/index.php @@ -0,0 +1,61 @@ + 5242880) { + http_response_code(500); + die("Error 500: File is too large. Maximum file size is 5MB."); +} + +// 验证上传的文件是否为 txt 格式 +$fileType = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $uploadData); +if ($fileType !== 'text/plain') { + http_response_code(500); + die("Error 500: Only plain text files (.txt) are allowed."); +} + +// 清理控制字符 +$uploadData = str_ireplace("\033[?25h", "", $uploadData); + +// 获取当前年份和月份 +$year = date('Y'); +$month = date('m'); + +// 构造存储目录 +$basePath = __DIR__ . "/"; +$directory = $basePath . $year . "/" . $month . "/"; + +// 创建目录(如果不存在) +if (!is_dir($directory) && !mkdir($directory, 0755, true)) { + http_response_code(500); + die("Error 500: Failed to create directory."); +} + +// 生成唯一文件名 +$fileName = "NL" . time() . "-" . strtoupper(substr(md5($uploadData), 0, 6)) . ".txt"; + +// 构造文件 URL +$baseUrl = getHttpType() . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']); +$filePath = $directory . $fileName; + +// 保存文件 +if (file_put_contents($filePath, $uploadData) === false) { + http_response_code(500); + die("Error 500: Failed to save the file."); +} + +// 返回文件 URL +echo $baseUrl . "/$year/$month/" . $fileName; diff --git a/version.sh b/version.sh index bcc62c3..2ed27d3 100644 --- a/version.sh +++ b/version.sh @@ -23,3 +23,4 @@ # 2024-09-08 v1.2.4 - 兼容新的接口。 # 2024-09-21 v1.2.5 - 修改bug。 # 2024-09-21 v1.2.6 - 删除融合怪。 +# 2025-01-21 v1.2.7 - 改用Curl命令,优化国内连接 \ No newline at end of file From b8b242a1c332a84b906b4c82424e2ca1fa56440b Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 01:45:18 +0800 Subject: [PATCH 02/13] tty --- Nlbench.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Nlbench.sh b/Nlbench.sh index 8e1e18a..12f6b05 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -544,8 +544,8 @@ main_menu() { echo -e "${YELLOW}2. 选择特定测试脚本${NC}" echo -e "${YELLOW}0. 退出${NC}" - # 提示输入并读取 - read -p "请选择操作 [0-2]: " choice + # 提示输入并读取,从终端读取输入 + read -p "请选择操作 [0-2]: " choice < /dev/tty # 确保输入非空 if [[ -z "$choice" ]]; then @@ -578,6 +578,7 @@ main_menu() { } + # 输出欢迎信息 show_welcome() { echo "" From b253805e1a642eed3ea5957ecf7ae77bca95c417 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 02:26:10 +0800 Subject: [PATCH 03/13] tty add --- Nlbench.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Nlbench.sh b/Nlbench.sh index 12f6b05..8a70355 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -421,10 +421,10 @@ run_script() { echo -e "运行${YELLOW}回程路由测试...${NC}" if [ "$use_ipv6" = true ]; then echo "使用IPv6测试选项" - wget -N --no-check-certificate https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "4" | tee "$temp_file" + wget -N --no-check-certificate https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" else echo "使用IPv4测试选项" - wget -N --no-check-certificate https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "1" | tee "$temp_file" + wget -N --no-check-certificate https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" fi sed -i -e 's/\x1B\[[0-9;]*[JKmsu]//g' -e '/No:1\/9 Traceroute to/,$!d' -e '/测试项/,+9d' -e '/信息/d' -e '/^\s*$/d' "$temp_file" cp "$temp_file" "${output_file}_route" @@ -515,7 +515,7 @@ run_selected_scripts() { echo "0. 返回" while true; do - read -p "请输入要执行的脚本编号(用英文逗号分隔,例如:1,2,3):" script_numbers + read -p "请输入要执行的脚本编号(用英文逗号分隔,例如:1,2,3):" script_numbers < /dev/tty if [[ "$script_numbers" =~ ^(0|10|[1-7])(,(0|10|[1-7]))*$ ]]; then break else From db715526523539d9fc4e56a1f62d8a5c99fc1e92 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 10:58:55 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Nlbench.sh | 8 +- server/bench.html | 357 ++++++++++++++++++++++++---------------------- 2 files changed, 190 insertions(+), 175 deletions(-) diff --git a/Nlbench.sh b/Nlbench.sh index 8a70355..e3ee724 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -460,10 +460,10 @@ generate_markdown_output() { done # 添加保留的空白标签 - for tab in "${empty_tabs[@]}"; do - echo "[tab=\"$tab\"]" >> "$temp_output_file" - echo "[/tab]" >> "$temp_output_file" - done + #for tab in "${empty_tabs[@]}"; do + # echo "[tab=\"$tab\"]" >> "$temp_output_file" + # echo "[/tab]" >> "$temp_output_file" + #done echo "[/tabs]" >> "$temp_output_file" diff --git a/server/bench.html b/server/bench.html index e6eed88..97083ad 100644 --- a/server/bench.html +++ b/server/bench.html @@ -3,213 +3,228 @@ - Nodeloc Bench Result - + 测试结果页面 + + +
+ 正在加载文件 +
+
+ + + - - - -
Loading...
- - - - - - - - - - - From a1aa7daa99d09f844b6a8066b38a3856a4f9ce31 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 11:10:57 +0800 Subject: [PATCH 05/13] run_selected_scripts --- Nlbench.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Nlbench.sh b/Nlbench.sh index e3ee724..bc2baf3 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -500,7 +500,6 @@ run_all_scripts() { clear } -# 执行选定的脚本 run_selected_scripts() { clear local base_output_file="NLvps_results_$(date +%Y%m%d_%H%M%S)" @@ -513,9 +512,9 @@ run_selected_scripts() { echo "6. 单线程测试" echo "7. 回程路由" echo "0. 返回" - + while true; do - read -p "请输入要执行的脚本编号(用英文逗号分隔,例如:1,2,3):" script_numbers < /dev/tty + read -p "请输入要执行的脚本编号(用英文逗号分隔,例如:1,2,3):" script_numbers < /dev/tty if [[ "$script_numbers" =~ ^(0|10|[1-7])(,(0|10|[1-7]))*$ ]]; then break else @@ -523,20 +522,26 @@ run_selected_scripts() { fi done - IFS=',' read -ra selected_scripts <<< "$script_numbers" - echo "开始执行选定的测试脚本..." - if [ "$script_numbers" == "0" ]; then + if [[ "$script_numbers" == "0" ]]; then clear show_welcome - else - for number in "${selected_scripts[@]}"; do - clear - run_script "$number" "$base_output_file" - done - generate_markdown_output "$base_output_file" + return # 确保退出函数,不再继续执行 fi + + # 分割用户输入为数组 + IFS=',' read -ra selected_scripts <<< "$script_numbers" + + echo "开始执行选定的测试脚本..." + for number in "${selected_scripts[@]}"; do + clear + run_script "$number" "$base_output_file" + done + + # 所有脚本执行完毕后生成 Markdown 输出 + generate_markdown_output "$base_output_file" } + # 主菜单 main_menu() { echo -e "${GREEN}测试项目:${NC}Yabs,IP质量,流媒体解锁,响应测试,多线程测试,单线程测试,回程路由。" From 51d408c112fb067785a6d72513dcc1dba696cb7c Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 11:57:18 +0800 Subject: [PATCH 06/13] tty 2 --- Nlbench.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nlbench.sh b/Nlbench.sh index bc2baf3..3bbdfd1 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -485,7 +485,7 @@ generate_markdown_output() { fi rm "$temp_output_file" - read -p "按回车键继续..." + read -p "按回车键继续..." < /dev/tty clear } From f70be8a35cc9b531b5cebbb3f3a08d533cdd7185 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 12:20:03 +0800 Subject: [PATCH 07/13] finish --- Cnbench.sh | 90 +++++++++++++++++++++++++++++++++--------------------- Nlbench.sh | 27 ++++++++-------- 2 files changed, 69 insertions(+), 48 deletions(-) diff --git a/Cnbench.sh b/Cnbench.sh index 20b2c94..5d78b50 100644 --- a/Cnbench.sh +++ b/Cnbench.sh @@ -4,7 +4,7 @@ CURRENT_VERSION="2025-01-21 v1.2.7" # 最新版本号 SCRIPT_URL="https://ghfast.top/https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/Nlbench.sh" VERSION_URL="https://ghfast.top/https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/version.sh" -CLOUD_SERVICE_BASE="https://bench.nodeloc.cc/" +CLOUD_SERVICE_BASE="https://bench.nodeloc.cc" # 定义颜色 RED='\033[0;31m' @@ -421,10 +421,10 @@ run_script() { echo -e "运行${YELLOW}回程路由测试...${NC}" if [ "$use_ipv6" = true ]; then echo "使用IPv6测试选项" - wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "4" | tee "$temp_file" + wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" else echo "使用IPv4测试选项" - wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "1" | tee "$temp_file" + wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" fi sed -i -e 's/\x1B\[[0-9;]*[JKmsu]//g' -e '/No:1\/9 Traceroute to/,$!d' -e '/测试项/,+9d' -e '/信息/d' -e '/^\s*$/d' "$temp_file" cp "$temp_file" "${output_file}_route" @@ -460,32 +460,33 @@ generate_markdown_output() { done # 添加保留的空白标签 - for tab in "${empty_tabs[@]}"; do - echo "[tab=\"$tab\"]" >> "$temp_output_file" - echo "[/tab]" >> "$temp_output_file" - done + #for tab in "${empty_tabs[@]}"; do + # echo "[tab=\"$tab\"]" >> "$temp_output_file" + # echo "[/tab]" >> "$temp_output_file" + #done echo "[/tabs]" >> "$temp_output_file" - # 上传文件 获取回调 - local plain_uploaded_file=$(cat ${temp_output_file}|curl -s -X POST --data-binary @- ${CLOUD_SERVICE_BASE}); - local plain_uploaded_file_filename=$(echo "$plain_uploaded_file" | grep -oP "$CLOUD_SERVICE_BASE\K.*") + local plain_uploaded_file=$(cat "${temp_output_file}" | curl -s -X POST --data-binary @- "${CLOUD_SERVICE_BASE}") + local plain_uploaded_file_path=$(echo "$plain_uploaded_file" | grep -oP "(?<=${CLOUD_SERVICE_BASE}).*") + local plain_uploaded_file_filename=$(basename "${plain_uploaded_file_path}") - - if [ $plain_uploaded_file ]; then - echo -e "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}\r\nPlain $plain_uploaded_file" > "$plain_uploaded_file_filename.url" - - echo "测试结果已上传,您可以在以下链接查看:" - echo "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}" - echo "Plain txt $plain_uploaded_file" - echo "结果链接已保存到 $plain_uploaded_file_filename.url" + if [ -n "$plain_uploaded_file" ]; then + local base_url=$(echo "${CLOUD_SERVICE_BASE}" | sed 's:/*$::') + local remote_url="${base_url}/result${plain_uploaded_file_path}" + echo -e "${remote_url}\r\nPlain ${plain_uploaded_file}" > "${plain_uploaded_file_filename}.url" + echo "测试结果已上传,您可以在以下链接查看:" + echo "${remote_url}" + echo "Plain ${plain_uploaded_file}" + echo "结果链接已保存到 ${plain_uploaded_file_filename}.url" else - echo "上传失败。结果已保存在本地文件 $temp_output_file" + echo "上传失败. 结果已保存在本地文件 ${temp_output_file}" fi + rm "$temp_output_file" - read -p "按回车键继续..." + read -p "按回车键继续..." < /dev/tty clear } @@ -500,7 +501,6 @@ run_all_scripts() { clear } -# 执行选定的脚本 run_selected_scripts() { clear local base_output_file="NLvps_results_$(date +%Y%m%d_%H%M%S)" @@ -513,9 +513,9 @@ run_selected_scripts() { echo "6. 单线程测试" echo "7. 回程路由" echo "0. 返回" - + while true; do - read -p "请输入要执行的脚本编号(用英文逗号分隔,例如:1,2,3):" script_numbers + read -p "请输入要执行的脚本编号(用英文逗号分隔,例如:1,2,3):" script_numbers < /dev/tty if [[ "$script_numbers" =~ ^(0|10|[1-7])(,(0|10|[1-7]))*$ ]]; then break else @@ -523,28 +523,46 @@ run_selected_scripts() { fi done - IFS=',' read -ra selected_scripts <<< "$script_numbers" - echo "开始执行选定的测试脚本..." - if [ "$script_numbers" == "0" ]; then + if [[ "$script_numbers" == "0" ]]; then clear show_welcome - else - for number in "${selected_scripts[@]}"; do - clear - run_script "$number" "$base_output_file" - done - generate_markdown_output "$base_output_file" + return # 确保退出函数,不再继续执行 fi + + # 分割用户输入为数组 + IFS=',' read -ra selected_scripts <<< "$script_numbers" + + echo "开始执行选定的测试脚本..." + for number in "${selected_scripts[@]}"; do + clear + run_script "$number" "$base_output_file" + done + + # 所有脚本执行完毕后生成 Markdown 输出 + generate_markdown_output "$base_output_file" } + # 主菜单 main_menu() { echo -e "${GREEN}测试项目:${NC}Yabs,IP质量,流媒体解锁,响应测试,多线程测试,单线程测试,回程路由。" echo -e "${YELLOW}1. 执行所有测试脚本${NC}" echo -e "${YELLOW}2. 选择特定测试脚本${NC}" echo -e "${YELLOW}0. 退出${NC}" - read -p "请选择操作 [0-2]: " choice + + # 提示输入并读取,从终端读取输入 + read -p "请选择操作 [0-2]: " choice < /dev/tty + # 确保输入非空 + if [[ -z "$choice" ]]; then + echo -e "${RED}输入为空,请重新输入。${NC}" + sleep 2s + clear + main_menu + return + fi + + # 检查输入是否合法 case $choice in 1) run_all_scripts @@ -558,13 +576,15 @@ main_menu() { ;; *) echo -e "${RED}无效选择,请重新输入。${NC}" - sleep 3s + sleep 2s clear - show_welcome + main_menu ;; esac } + + # 输出欢迎信息 show_welcome() { echo "" diff --git a/Nlbench.sh b/Nlbench.sh index 3bbdfd1..e6c5750 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -4,7 +4,7 @@ CURRENT_VERSION="2025-01-21 v1.2.7" # 最新版本号 SCRIPT_URL="https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/Nlbench.sh" VERSION_URL="https://raw.githubusercontent.com/nodeloc/nodeloc_vps_test/main/version.sh" -CLOUD_SERVICE_BASE="https://bench.nodeloc.cc/" +CLOUD_SERVICE_BASE="https://bench.nodeloc.cc" # 定义颜色 RED='\033[0;31m' @@ -467,23 +467,24 @@ generate_markdown_output() { echo "[/tabs]" >> "$temp_output_file" - # 上传文件 获取回调 - local plain_uploaded_file=$(cat ${temp_output_file}|curl -s -X POST --data-binary @- ${CLOUD_SERVICE_BASE}); - local plain_uploaded_file_filename=$(echo "$plain_uploaded_file" | grep -oP "$CLOUD_SERVICE_BASE\K.*") + local plain_uploaded_file=$(cat "${temp_output_file}" | curl -s -X POST --data-binary @- "${CLOUD_SERVICE_BASE}") + local plain_uploaded_file_path=$(echo "$plain_uploaded_file" | grep -oP "(?<=${CLOUD_SERVICE_BASE}).*") + local plain_uploaded_file_filename=$(basename "${plain_uploaded_file_path}") - - if [ $plain_uploaded_file ]; then - echo -e "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}\r\nPlain $plain_uploaded_file" > "$plain_uploaded_file_filename.url" - - echo "测试结果已上传,您可以在以下链接查看:" - echo "${CLOUD_SERVICE_BASE}result/${plain_uploaded_file_filename}" - echo "Plain $plain_uploaded_file" - echo "结果链接已保存到 $plain_uploaded_file_filename.url" + if [ -n "$plain_uploaded_file" ]; then + local base_url=$(echo "${CLOUD_SERVICE_BASE}" | sed 's:/*$::') + local remote_url="${base_url}/result${plain_uploaded_file_path}" + echo -e "${remote_url}\r\nPlain ${plain_uploaded_file}" > "${plain_uploaded_file_filename}.url" + echo "测试结果已上传,您可以在以下链接查看:" + echo "${remote_url}" + echo "Plain ${plain_uploaded_file}" + echo "结果链接已保存到 ${plain_uploaded_file_filename}.url" else - echo "上传失败。结果已保存在本地文件 $temp_output_file" + echo "上传失败. 结果已保存在本地文件 ${temp_output_file}" fi + rm "$temp_output_file" read -p "按回车键继续..." < /dev/tty clear From a33fa6578e0e041796289fd0820d13bfa1050966 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 12:35:30 +0800 Subject: [PATCH 08/13] Change to autotrace --- Nlbench.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nlbench.sh b/Nlbench.sh index e6c5750..edde5e4 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -421,10 +421,10 @@ run_script() { echo -e "运行${YELLOW}回程路由测试...${NC}" if [ "$use_ipv6" = true ]; then echo "使用IPv6测试选项" - wget -N --no-check-certificate https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" + wget -N --no-check-certificate https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "4" | tee "$temp_file" else echo "使用IPv4测试选项" - wget -N --no-check-certificate https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" + wget -N --no-check-certificate https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "1" | tee "$temp_file" fi sed -i -e 's/\x1B\[[0-9;]*[JKmsu]//g' -e '/No:1\/9 Traceroute to/,$!d' -e '/测试项/,+9d' -e '/信息/d' -e '/^\s*$/d' "$temp_file" cp "$temp_file" "${output_file}_route" From 2199b3fe6756bbf1cc4b70227660bab38080f406 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 12:36:17 +0800 Subject: [PATCH 09/13] change to ghfast.top --- Cnbench.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cnbench.sh b/Cnbench.sh index 5d78b50..3345bdb 100644 --- a/Cnbench.sh +++ b/Cnbench.sh @@ -421,10 +421,10 @@ run_script() { echo -e "运行${YELLOW}回程路由测试...${NC}" if [ "$use_ipv6" = true ]; then echo "使用IPv6测试选项" - wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" + wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "4" | tee "$temp_file" else echo "使用IPv4测试选项" - wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/zq/shell/master/autoBestTrace.sh && chmod +x autoBestTrace.sh && bash autoBestTrace.sh | tee "$temp_file" + wget -N --no-check-certificate https://ghfast.top/https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh <<< "1" | tee "$temp_file" fi sed -i -e 's/\x1B\[[0-9;]*[JKmsu]//g' -e '/No:1\/9 Traceroute to/,$!d' -e '/测试项/,+9d' -e '/信息/d' -e '/^\s*$/d' "$temp_file" cp "$temp_file" "${output_file}_route" From 2f3dc9ef797f20f915be2f7c25e2136bd192c89d Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 12:46:26 +0800 Subject: [PATCH 10/13] version 1.0 --- server/bench.html | 263 ++++++++++++++++++++++++++++++++++++++++++++++ server/index.php | 2 +- 2 files changed, 264 insertions(+), 1 deletion(-) diff --git a/server/bench.html b/server/bench.html index 97083ad..bee3fe2 100644 --- a/server/bench.html +++ b/server/bench.html @@ -229,3 +229,266 @@ + + + + + + 测试结果页面 + + +
+ 正在加载文件 +
+
+ + + + + + + + + + diff --git a/server/index.php b/server/index.php index c521dfc..2d98810 100644 --- a/server/index.php +++ b/server/index.php @@ -48,7 +48,7 @@ if (!is_dir($directory) && !mkdir($directory, 0755, true)) { $fileName = "NL" . time() . "-" . strtoupper(substr(md5($uploadData), 0, 6)) . ".txt"; // 构造文件 URL -$baseUrl = getHttpType() . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']); +$baseUrl = rtrim(getHttpType() . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']), '/'); // 去掉末尾多余的斜杠 $filePath = $directory . $fileName; // 保存文件 From 3e19b744970a4884e1f1ae9881ff0f6b8745e759 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 12:52:36 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E5=8F=96=E6=B6=88=E4=BA=92=E5=8A=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cnbench.sh | 2 ++ Nlbench.sh | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cnbench.sh b/Cnbench.sh index 3345bdb..1c1a313 100644 --- a/Cnbench.sh +++ b/Cnbench.sh @@ -251,6 +251,8 @@ install_dependencies() { done ;; *) + install_cmd="apt-get install -yq" + export DEBIAN_FRONTEND=noninteractive for dep in "${dependencies[@]}"; do if ! command -v "$dep" &> /dev/null; then echo -e "${YELLOW}正在安装 $dep...${NC}" diff --git a/Nlbench.sh b/Nlbench.sh index edde5e4..4f40c7e 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -202,7 +202,6 @@ update_system() { # 定义支持的操作系统类型 SUPPORTED_OS=("ubuntu" "debian" "linuxmint" "elementary" "pop" "centos" "rhel" "fedora" "rocky" "almalinux" "openeuler" "opensuse" "sles" "arch" "manjaro" "alpine" "gentoo" "cloudlinux") -# 安装依赖 install_dependencies() { echo -e "${YELLOW}正在检查并安装必要的依赖项...${NC}" @@ -225,11 +224,11 @@ install_dependencies() { case "${os_type,,}" in gentoo) - install_cmd="emerge" + install_cmd="emerge --quiet" for dep in "${dependencies[@]}"; do - if ! emerge -p $dep &>/dev/null; then + if ! emerge -p "$dep" &>/dev/null; then echo -e "${YELLOW}正在安装 $dep...${NC}" - if ! sudo $install_cmd $dep; then + if ! sudo $install_cmd "$dep"; then echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" fi else @@ -238,9 +237,9 @@ install_dependencies() { done ;; alpine) - install_cmd="apk add" + install_cmd="apk add --no-cache" for dep in "${dependencies[@]}"; do - if ! command -v "$dep" &> /dev/null; then + if ! command -v "$dep" &>/dev/null; then echo -e "${YELLOW}正在安装 $dep...${NC}" if ! sudo $install_cmd "$dep"; then echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" @@ -251,8 +250,10 @@ install_dependencies() { done ;; *) + install_cmd="apt-get install -yq" + export DEBIAN_FRONTEND=noninteractive for dep in "${dependencies[@]}"; do - if ! command -v "$dep" &> /dev/null; then + if ! command -v "$dep" &>/dev/null; then echo -e "${YELLOW}正在安装 $dep...${NC}" if ! sudo $install_cmd "$dep"; then echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" @@ -268,6 +269,7 @@ install_dependencies() { clear } + # 获取IP地址和ISP信息 ip_address_and_isp() { ipv4_address=$(curl -s --max-time 5 ipv4.ip.sb) From af8ed99ba41c0d9d54d5531dd5227f01337c63e1 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 12:56:52 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E4=BA=A4=E4=BA=92=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cnbench.sh | 67 ++++++++++++++++++++++++------------------------------ Nlbench.sh | 65 ++++++++++++++++++++++++---------------------------- 2 files changed, 60 insertions(+), 72 deletions(-) diff --git a/Cnbench.sh b/Cnbench.sh index 1c1a313..2f0ce34 100644 --- a/Cnbench.sh +++ b/Cnbench.sh @@ -202,7 +202,6 @@ update_system() { # 定义支持的操作系统类型 SUPPORTED_OS=("ubuntu" "debian" "linuxmint" "elementary" "pop" "centos" "rhel" "fedora" "rocky" "almalinux" "openeuler" "opensuse" "sles" "arch" "manjaro" "alpine" "gentoo" "cloudlinux") -# 安装依赖 install_dependencies() { echo -e "${YELLOW}正在检查并安装必要的依赖项...${NC}" @@ -224,50 +223,44 @@ install_dependencies() { fi case "${os_type,,}" in - gentoo) - install_cmd="emerge" - for dep in "${dependencies[@]}"; do - if ! emerge -p $dep &>/dev/null; then - echo -e "${YELLOW}正在安装 $dep...${NC}" - if ! sudo $install_cmd $dep; then - echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" - fi - else - echo -e "${GREEN}$dep 已安装。${NC}" - fi - done + debian|ubuntu) + export DEBIAN_FRONTEND=noninteractive # 禁用交互 + install_cmd="apt-get install -yq" + sudo apt-get update -yq + ;; + centos|rhel|fedora) + install_cmd="dnf install -y" + sudo dnf makecache ;; alpine) - install_cmd="apk add" - for dep in "${dependencies[@]}"; do - if ! command -v "$dep" &> /dev/null; then - echo -e "${YELLOW}正在安装 $dep...${NC}" - if ! sudo $install_cmd "$dep"; then - echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" - fi - else - echo -e "${GREEN}$dep 已安装。${NC}" - fi - done + install_cmd="apk add --no-cache" + ;; + gentoo) + install_cmd="emerge --quiet" + ;; + arch|manjaro) + install_cmd="pacman -S --noconfirm" + sudo pacman -Sy --noconfirm ;; *) - install_cmd="apt-get install -yq" - export DEBIAN_FRONTEND=noninteractive - for dep in "${dependencies[@]}"; do - if ! command -v "$dep" &> /dev/null; then - echo -e "${YELLOW}正在安装 $dep...${NC}" - if ! sudo $install_cmd "$dep"; then - echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" - fi - else - echo -e "${GREEN}$dep 已安装。${NC}" - fi - done + echo -e "${RED}未知的包管理器。请手动安装依赖项。${NC}" + return 1 ;; esac + + # 安装依赖项 + for dep in "${dependencies[@]}"; do + if ! command -v "$dep" &>/dev/null; then + echo -e "${YELLOW}正在安装 $dep...${NC}" + if ! sudo $install_cmd "$dep"; then + echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" + fi + else + echo -e "${GREEN}$dep 已安装。${NC}" + fi + done echo -e "${GREEN}依赖项检查和安装完成。${NC}" - clear } # 获取IP地址和ISP信息 diff --git a/Nlbench.sh b/Nlbench.sh index 4f40c7e..9782eb7 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -223,53 +223,48 @@ install_dependencies() { fi case "${os_type,,}" in - gentoo) - install_cmd="emerge --quiet" - for dep in "${dependencies[@]}"; do - if ! emerge -p "$dep" &>/dev/null; then - echo -e "${YELLOW}正在安装 $dep...${NC}" - if ! sudo $install_cmd "$dep"; then - echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" - fi - else - echo -e "${GREEN}$dep 已安装。${NC}" - fi - done + debian|ubuntu) + export DEBIAN_FRONTEND=noninteractive # 禁用交互 + install_cmd="apt-get install -yq" + sudo apt-get update -yq + ;; + centos|rhel|fedora) + install_cmd="dnf install -y" + sudo dnf makecache ;; alpine) install_cmd="apk add --no-cache" - for dep in "${dependencies[@]}"; do - if ! command -v "$dep" &>/dev/null; then - echo -e "${YELLOW}正在安装 $dep...${NC}" - if ! sudo $install_cmd "$dep"; then - echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" - fi - else - echo -e "${GREEN}$dep 已安装。${NC}" - fi - done + ;; + gentoo) + install_cmd="emerge --quiet" + ;; + arch|manjaro) + install_cmd="pacman -S --noconfirm" + sudo pacman -Sy --noconfirm ;; *) - install_cmd="apt-get install -yq" - export DEBIAN_FRONTEND=noninteractive - for dep in "${dependencies[@]}"; do - if ! command -v "$dep" &>/dev/null; then - echo -e "${YELLOW}正在安装 $dep...${NC}" - if ! sudo $install_cmd "$dep"; then - echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" - fi - else - echo -e "${GREEN}$dep 已安装。${NC}" - fi - done + echo -e "${RED}未知的包管理器。请手动安装依赖项。${NC}" + return 1 ;; esac + + # 安装依赖项 + for dep in "${dependencies[@]}"; do + if ! command -v "$dep" &>/dev/null; then + echo -e "${YELLOW}正在安装 $dep...${NC}" + if ! sudo $install_cmd "$dep"; then + echo -e "${RED}无法安装 $dep。请手动安装此依赖项。${NC}" + fi + else + echo -e "${GREEN}$dep 已安装。${NC}" + fi + done echo -e "${GREEN}依赖项检查和安装完成。${NC}" - clear } + # 获取IP地址和ISP信息 ip_address_and_isp() { ipv4_address=$(curl -s --max-time 5 ipv4.ip.sb) From 3bed8f5f7f991a27c3641e02107e1ad1144be716 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 21 Jan 2025 12:59:01 +0800 Subject: [PATCH 13/13] update --- Cnbench.sh | 1 + Nlbench.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cnbench.sh b/Cnbench.sh index 2f0ce34..cc7543b 100644 --- a/Cnbench.sh +++ b/Cnbench.sh @@ -225,6 +225,7 @@ install_dependencies() { case "${os_type,,}" in debian|ubuntu) export DEBIAN_FRONTEND=noninteractive # 禁用交互 + echo "iperf3 iperf3/autostart boolean false" | sudo debconf-set-selections install_cmd="apt-get install -yq" sudo apt-get update -yq ;; diff --git a/Nlbench.sh b/Nlbench.sh index 9782eb7..87a9b4d 100644 --- a/Nlbench.sh +++ b/Nlbench.sh @@ -224,7 +224,8 @@ install_dependencies() { case "${os_type,,}" in debian|ubuntu) - export DEBIAN_FRONTEND=noninteractive # 禁用交互 + export DEBIAN_FRONTEND=noninteractive + echo "iperf3 iperf3/autostart boolean false" | sudo debconf-set-selections install_cmd="apt-get install -yq" sudo apt-get update -yq ;;