#!/bin/bash domain=”live-push.bilivideo.com” # 解析域名的所有A记录 ips=($(dig +short $domain | grep -E ‘^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$’)) # 测试延迟并选择最低延迟的IP地址 lowest_latency=”” lowest_latency_value=9999 for ip in “${ips[@]}” do # 测试延迟 latency=$(ping -c 5 -q $ip | grep rtt | awk -F/ ‘{print $5}’) # 比较延迟 if (( $(bc <<< "$latency < $lowest_latency_value") )) then lowest_latency_value=$latency lowest_latency=$ip fi done echo "最低延迟的IP地址: $lowest_latency" echo "延迟值: $lowest_latency_value ms"复制代码
chatgpt 生成