From 40f0ebb1a69e4fc531a37102253ca6471c5d063e Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Sun, 23 Feb 2025 00:04:47 -0800 Subject: less code --- sh/dnd | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sh/dnd b/sh/dnd index f6aee4a..da1d48f 100755 --- a/sh/dnd +++ b/sh/dnd @@ -19,20 +19,21 @@ done shift $((OPTIND-1)) if [ "$1" ]; then + ns="@$1" echo "$1" else + ns= echo "default" 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)}' - elif "$resolved"; then + if "$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)}' + # "$ns" will "Error: error in making qname", so use $ns + drill -- "$domain" $ns | awk -F: -v domain="$domain" '/^;; Query time: /{printf("%s%s\n",domain,$2)}' fi done -- cgit v1.2.3-70-g09d2