複数のDNSに対して一度に問い合わせするワンライナー

追記:
スクリプトに書き直してみたので記事を挙げてみた。

作業メモ

0.作業ディレクトリを作成

$ mkdir -p `date +%Y%m%d` && cd `date +%Y%m%d`

1.参照するDNSサーバーを[dns]というテキストファイルに書き出す

$ cat dns

テキストファイル:dnsの中身

8.8.8.8
9.9.9.10

2.dnsを参照してhostコマンドで名前解決するスクリプトを実行

$ for i in `cat dns` ; do echo "######### $i #########" && host g.cn $i | sort -n ; done >> `date +%y%m%d%H%M%S`

3.内容を確認

$ cat 210515015159

内容は問題なし。

ドメイン:g.cnは、DNSラウンドロビンされているので8.8.8.8と9.9.9.10で値が違う。


######### 8.8.8.8 #########

Address: 8.8.8.8#53
Aliases:
g.cn has address 172.217.31.131
g.cn has IPv6 address 2404:6800:4004:808::2003
g.cn mail is handled by 10 aspmx.l.google.com.
g.cn mail is handled by 20 alt1.aspmx.l.google.com.
g.cn mail is handled by 30 alt2.aspmx.l.google.com.
g.cn mail is handled by 40 alt3.aspmx.l.google.com.
g.cn mail is handled by 50 alt4.aspmx.l.google.com.
Name: 8.8.8.8
Using domain server:
######### 9.9.9.10 #########

Address: 9.9.9.10#53
Aliases:
g.cn has address 172.217.25.67
g.cn has IPv6 address 2404:6800:4004:812::2003
g.cn mail is handled by 10 aspmx.l.google.com.
g.cn mail is handled by 20 alt1.aspmx.l.google.com.
g.cn mail is handled by 30 alt2.aspmx.l.google.com.
g.cn mail is handled by 40 alt3.aspmx.l.google.com.
g.cn mail is handled by 50 alt4.aspmx.l.google.com.
Name: 9.9.9.10
Using domain server:

応用編、というかメモ

出力結果のハッシュ値を出力したい場合は結果をmd5sumに食わせたらOK。

$ for i in `cat dns` ; do echo "######### $i #########" && host g.cn $i | sort -n ; done | md5sum
92b18c5af21e2ade262d3934cb740118  -

コメント

タイトルとURLをコピーしました