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
#!/bin/bash
# 使用方法: ./curl_test.sh <域名> <测试次数>
if [ $# -lt 2 ]; then
echo "Usage: $0 <domain> <times>"
exit 1
fi
DOMAIN=$1
TIMES=$2
# 保存每次总耗时
times_arr=()
echo "Testing $DOMAIN $TIMES times..."
for i in $(seq 1 $TIMES); do
# 获取各阶段时间
output=$(curl -o /dev/null -s -w "
time_namelookup: %{time_namelookup}s
time_connect: %{time_connect}s
time_appconnect: %{time_appconnect}s
time_pretransfer: %{time_pretransfer}s
time_starttransfer: %{time_starttransfer}s
time_total: %{time_total}s
" https://$DOMAIN)
# 提取总耗时
total_time=$(echo "$output" | grep "time_total" | awk '{print $2}' | sed 's/s//')
times_arr+=($total_time)
echo "Run #$i:"
echo "$output"
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 "-----------------------------"
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
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