summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2025-02-22 23:52:00 -0800
committerXiao Pan <xyz@flylightning.xyz>2025-02-22 23:52:00 -0800
commitb91ef99fc098adc858de959318505af43bdd9323 (patch)
treee69e65a542524ea751ba5af48fe17a5e877d9ca8
parent2d015f2dbeeb23ad40ca2610b1c5df3abeaf1313 (diff)
Consider no systemd-resolved
-rwxr-xr-xsh/dnd10
1 files changed, 9 insertions, 1 deletions
diff --git a/sh/dnd b/sh/dnd
index 1fa6f7b..f6aee4a 100755
--- a/sh/dnd
+++ b/sh/dnd
@@ -4,6 +4,12 @@
# Usage: dnd, dnd -c, dnd 192.168.0.1, dnd 8.8.8.8
cache=false
+if resolvectl status >/dev/null 2>&1; then
+ resolved=true
+else
+ resolved=false
+fi
+
while getopts c opt; do
case $opt in
c)cache=true;;
@@ -21,10 +27,12 @@ fi
for domain in www.google.com www.baidu.com github.com gitlab.com codeberg.org www.douyu.com flylightning.xyz mirrors.flylightning.xyz git.flylightning.xyz mail.flylightning.xyz one.sjsu.edu discord.com www.youtube.com mail.google.com mail.yahoo.com en.wikipedia.org zh.wikipedia.org archlinux.org gitlab.archlinux.org aur.archlinux.org wiki.archlinux.org wiki.gentoo.org unix.stackexchange.com stackoverflow.com superuser.com www.reddit.com kyun.host panel.ihostart.com virt.crunchbits.com; do
if [ "$1" ]; then
drill -- "$domain" "@$1" | awk -F: -v domain="$domain" '/^;; Query time: /{printf("%s%s\n",domain,$2)}'
- else
+ elif "$resolved"; then
# awk substr and length:
# https://stackoverflow.com/a/14840991
# https://unix.stackexchange.com/a/305192
resolvectl --cache="$cache" query "$domain" | awk -v domain="$domain" '/Information acquired via protocol DNS in/{printf("%s %s\n",domain,substr($NF,0,length($NF)-1))}'
+ else
+ drill -- "$domain" | awk -F: -v domain="$domain" '/^;; Query time: /{printf("%s%s\n",domain,$2)}'
fi
done