Files
dock/测速中文
2025-10-28 14:23:33 +08:00

28 lines
953 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
echo "🚀 一键网络测速"
# 检查并安装必要工具
if ! command -v bc &> /dev/null; then
echo "安装必要工具..."
apt-get update > /dev/null 2>&1 && apt-get install -y bc > /dev/null 2>&1
fi
# 延迟测试 - 10次ping取平均值
echo "🔄 测试网络延迟..."
ping_result=$(ping -c 10 8.8.8.8 | tail -1)
if echo "$ping_result" | grep -q "/"; then
avg_ping=$(echo "$ping_result" | awk -F'/' '{print $5}')
echo "网络延迟: $avg_ping ms"
else
echo "网络延迟: 测试失败"
fi
# 下载速度测试 - 使用 wget 显示实时速度
echo "⬇️ 测试下载速度10秒..."
echo "正在下载测试文件..."
# 使用 wget 并显示进度(会自动显示速度)
wget -O /dev/null --progress=dot:giga --timeout=15 http://cachefly.cachefly.net/100mb.test 2>&1 | grep --line-buffered -oP '\d+\.\d+ [KM]B/s' | tail -1 | awk '{print "平均下载速度: " $1 " " $2}'
echo "✅ 测速完成"