Latency
Time Cost
curl -o /dev/null -s -w"
time_namelookup: %{time_namelookup}s\n\
time_connect: %{time_connect}s\n\
time_appconnect: %{time_appconnect}s\n\
time_pretransfer: %{time_pretransfer}s\n\
time_starttransfer: %{time_starttransfer}s\n\
time_total: %{time_total}s\n" https://www.fnnas.com
time_namelookup: 0.030327s
time_connect: 0.062180s
time_appconnect: 0.135421s
time_pretransfer: 0.135541s
time_starttransfer: 0.193158s
time_total: 0.414906s
Get Public IP
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 0a:58:74:a9:33:0a brd ff:ff:ff:ff:ff:ff
altname enp2s0
inet 110.x.x.x/24 brd 110.185.110.255 scope global eth1
valid_lft forever preferred_lft forever
inet 112.x.x.x/24 brd 112.19.8.255 scope global eth1
valid_lft forever preferred_lft forever
inet 116.x.x.x/24 brd 116.169.51.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::858:74ff:fea9:330a/64 scope link
valid_lft forever preferred_lft forever
110.x.x.x/24
:电信
112.x.x.x/24
:移动
116.x.x.x/24
:联通
Specify CURL IP
curl -o /dev/null -s -w "%{time_total}\n" --interface 116.x.x.x https://www.fnnas.com
curl -o /dev/null -s --interface 116.x.x.x -w"
time_namelookup: %{time_namelookup}s\n\
time_connect: %{time_connect}s\n\
time_appconnect: %{time_appconnect}s\n\
time_pretransfer: %{time_pretransfer}s\n\
time_starttransfer: %{time_starttransfer}s\n\
time_total: %{time_total}s\n" https://www.fnnas.com
tcpdump -i eth1 host fnnas.com and port 443 -n
Testing Script
#!/bin/bash
# 使用方法: ./curl_test.sh <域名> <测试次数> [出口IP]
if [ $# -lt 2 ]; then
echo "Usage: $0 <domain> <times> [egress_ip]"
exit 1
fi
DOMAIN=$1
TIMES=$2
EGRESS_IP=$3 # 可选
times_arr=()
echo "Testing $DOMAIN $TIMES times..."
echo "-----------------------------"
for i in $(seq 1 $TIMES); do
# 构造 curl 命令
CURL_CMD="curl -o /dev/null -s"
[ -n "$EGRESS_IP" ] && CURL_CMD="$CURL_CMD --interface $EGRESS_IP"
CURL_CMD="$CURL_CMD -w \"time_namelookup: %{time_namelookup}s\n\
time_connect: %{time_connect}s\n\
time_appconnect: %{time_appconnect}s\n\
time_pretransfer: %{time_pretransfer}s\n\
time_starttransfer: %{time_starttransfer}s\n\
time_total: %{time_total}s\n\" https://$DOMAIN"
# 执行 curl
output=$(eval $CURL_CMD)
# 提取总耗时
total_time=$(echo "$output" | grep "time_total" | awk '{print $2}' | sed 's/s//')
times_arr+=($total_time)
# 打印每次 run 的输出
echo "Run #$i:"
printf "%s\n" "$output"
echo "-----------------------------"
done
# 计算平均、最大、最小值
sum=0
max=${times_arr[0]}
min=${times_arr[0]}
for t in "${times_arr[@]}"; do
sum=$(echo "$sum + $t" | bc)
(( $(echo "$t > $max" | bc -l) )) && max=$t
(( $(echo "$t < $min" | bc -l) )) && min=$t
done
avg=$(echo "scale=3; $sum / $TIMES" | bc)
echo "Summary for $DOMAIN after $TIMES runs:"
echo "Average total time: $avg s"
echo "Fastest total time: $min s"
echo "Slowest total time: $max s"
./curl-test.sh www.fnnas.com 5 [出口IP(可选)]
No comments to display
No comments to display