Skip to content

Commit df069b3

Browse files
committed
Added support for DNS to the IP addresses script.
1 parent 7245ce3 commit df069b3

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ wget -qO - https://raw.github.com/tdulcet/Linux-System-Information/master/typein
9393

9494
### Public IP addresses
9595

96-
Outputs your public IP addresses using a couple dozen different services to find the one with the best HTTPS response times on your network.
96+
Outputs your public IP addresses using a couple dozen different services to find the one with the best HTTPS and DNS response times on your network.
9797

9898
```bash
9999
wget -qO - https://raw.github.com/tdulcet/Linux-System-Information/master/ipinfo.sh | bash -s

ipinfo.sh

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
# wget -qO - https://raw.github.com/tdulcet/Linux-System-Information/master/ipinfo.sh | bash -s --
66
# ./ipinfo.sh
77

8-
# Adapted from: https://github.com/rsp/scripts/blob/master/externalip.md
8+
# Adapted from: https://github.com/rsp/scripts/blob/master/externalip-benchmark.md
99

1010
if [[ $# -ne 0 ]]; then
1111
echo "Usage: $0" >&2
1212
exit 1
1313
fi
1414

15-
urls=(
15+
URLS=(
1616
alma.ch/myip.cgi
1717
api.ipify.org/
1818
# bot.whatismyipaddress.com/
@@ -25,7 +25,7 @@ urls=(
2525
icanhazip.com/
2626
ident.me/ # v4.ident.me/ # v6.ident.me/
2727
ifconfig.co/
28-
ifconfig.me/
28+
ifconfig.me/ip
2929
ifconfig.pro/
3030
ipaddr.site/
3131
ipecho.net/plain
@@ -34,26 +34,87 @@ urls=(
3434
ip.tyk.nu/
3535
l2.io/ip
3636
# myip.addr.space/
37-
# tnx.nl/ip
37+
tnx.nl/ip
3838
wgetip.com/
3939
ifconfig.io/ip
4040
silisoftware.com/tools/ip.php
41+
corz.org/ip
42+
ifcfg.me/
43+
api.infoip.io/ip
44+
whatismyip.akamai.com/
45+
ip-adresim.app/
46+
ipaddress.sh/
47+
myexternalip.com/raw
48+
myip.dnsomatic.com/
49+
trackip.net/ip
50+
wtfismyip.com/text
51+
myip.wtf/text
52+
ipapi.co/ip
53+
ip2location.io/ip
54+
checkip.spdyn.de/
55+
www.nsupdate.info/myip
56+
ip.changeip.com/
4157
# gso.cs.pdx.edu/ip/
4258
)
4359

60+
SERVERS=(
61+
one.one.one.one
62+
dns.opendns.com
63+
resolver{1..4}.opendns.com
64+
ns1-1.akamaitech.net
65+
ns{1..4}.google.com
66+
)
67+
68+
NAMES=(
69+
whoami.cloudflare
70+
myip.opendns.com
71+
myip.opendns.com{,,,}
72+
whoami.akamai.net
73+
o-o.myaddr.l.google.com{,,,}
74+
)
75+
76+
TYPES=(
77+
TXT
78+
''
79+
''{,,,}
80+
''
81+
''{,,,}
82+
)
83+
84+
CLASSES=(
85+
CH
86+
''
87+
''{,,,}
88+
''
89+
''{,,,}
90+
)
91+
4492
echo -e "\nPublic IP addresses"
4593

4694
for ip in 4 6; do
47-
echo -e "\nIPv$ip address Best HTTPS response times:\n"
95+
echo -e "\nBest HTTPS response times IPv$ip address:\n"
96+
97+
for url in "${URLS[@]}"; do
98+
answer=''
99+
if output=$(curl -"$ip" -m10 -sSfLw '\n%{time_total}\n' "https://$url" 2>&1); then
100+
answer=$(echo "$output" | head -n 1)
101+
fi
102+
time=$(echo "$output" | tail -n 1)
103+
printf '%s seconds \thttps://%s\t%s\n' "$time" "$url" "${answer:--}"
104+
done | sort -n | awk -F'[ ]' '{ $1 *= 1000; $2 = "ms"; print }' | column -t -s $'\t'
105+
done
106+
107+
for ip in 4 6; do
108+
echo -e "\nBest DNS response times IPv$ip address:\n"
48109

49-
for url in "${urls[@]}"; do
110+
for i in "${!SERVERS[@]}"; do
50111
answer=''
51-
if cout=$(curl -"$ip" -m10 -sSLw '\n%{time_total}\n' "https://$url" 2>&1); then
52-
answer=$(echo "$cout" | head -n 1)
112+
if output=$(dig -"$ip" -u "@${SERVERS[i]}" "${NAMES[i]}" "${TYPES[i]:-IN}" "${CLASSES[i]:-ANY}" 2>&1); then
113+
answer=$(echo "$output" | grep -v '^;' | awk '$4 == "A" || $4 == "AAAA" || $4 == "TXT" { print $4"\t"$5 }' | head -n 1)
53114
fi
54-
time=$(echo "$cout" | tail -n 1)
55-
printf '%s seconds\thttps://%s\t%s\n' "$time" "$url" "${answer:--}"
56-
done | sort -n | column -t -s $'\t'
115+
time=$(echo "$output" | sed -n 's/;; Query time: *//p')
116+
printf '%s \t%s\t%s\t%s\n' "${time:-0 usec}" "${SERVERS[i]}" "${NAMES[i]}" "${answer:--}"
117+
done | sort -n | awk -F'[ ]' '{ $1 /= 1000; $2 = "ms"; print }' | column -t -s $'\t'
57118
done
58119

59120
echo

0 commit comments

Comments
 (0)