Yen*_*eng 8 command-line scripts dns ip
有没有办法检查反向 DNS 检查是否有大量 IP,我有一个要检查的 IP 列表?
我知道您可以单独执行这些操作:
host <ip-address>
Run Code Online (Sandbox Code Playgroud)
和
dig -x <ip-address>
Run Code Online (Sandbox Code Playgroud)
另外,有没有办法导出它们?
Ser*_*nyy 10
xargs
提供了一个 optin --arg-file
。随着-L1
选项,可将每行作为参数,我们可以做出简单的命令如下
$ xargs -L1 --arg-file=ip-addr.txt dig +short -x
google-public-dns-a.google.com.
resolver2.opendns.com.
Run Code Online (Sandbox Code Playgroud)
如果需要在解析的域旁边显示IP地址,我们也可以这样做:
$ xargs -L1 --arg-file=ip-addr.txt sh -c 'printf "%s: " "$1"; dig +short -x "$1"' sh
8.8.8.8: google-public-dns-a.google.com.
208.67.220.220: resolver2.opendns.com.
Run Code Online (Sandbox Code Playgroud)
当然,xargs
是一个额外的过程。如果我们只想使用 shell 和dig
? 对于 bash 版本 4 及以上版本,我们可以使用mapfile
或readarray
将文本文件的行放入数组中,然后循环处理项目:
$ mapfile -t -d $'\n' < ip-addr.txt
$ for i in "${MAPFILE[@]}" ; do printf "%s:" "$i"; dig +short -x "$i"; done
8.8.8.8:google-public-dns-a.google.com.
208.67.220.220:resolver2.opendns.com.
Run Code Online (Sandbox Code Playgroud)
如果 IP 地址很少并且不需要长文本文件,POSIXly,我们可以使用set
将值定义为位置参数:
$ set -- 8.8.8.8 208.67.220.220
$ for i ; do printf "%s:" "$i"; dig +short -x "$i"; done
8.8.8.8:google-public-dns-a.google.com.
208.67.220.220:resolver2.opendns.com.
Run Code Online (Sandbox Code Playgroud)
我们也可以dig -x $IP_ADDRESS +short
像这样在脚本中使用:
$ xargs -L1 --arg-file=ip-addr.txt dig +short -x
google-public-dns-a.google.com.
resolver2.opendns.com.
Run Code Online (Sandbox Code Playgroud)
示例使用演示(所有 ip 地址均以空格分隔):
$ ./reverse_dns_lookup.sh 8.8.8.8 74.125.193.94 151.101.193.69
google-public-dns-a.google.com.
ig-in-f94.1e100.net.
151.101.193.69 result is NULL
Run Code Online (Sandbox Code Playgroud)
如您所见,在上一个示例中,我们的 DNS 服务器没有找到我们提供的 IP 地址的域。在这种情况下,我们可以使用不同的 DNS 服务器,例如 open_dnsdig @208.67.220.220 $IP_ADDRESS +short
在上面的演示中,ip 地址是在命令行上提供的,就像./reverse_dns_lookup.sh ADDRESS1 ADDRESS2 ADDRESS2
但你也可以使用一个文件,像这样:
$ cat ip_addresses.txt | xargs ./reverse_dns_lookup.sh <
google-public-dns-a.google.com.
resolver2.opendns.com.
192.30.253.112 result is NULL
Run Code Online (Sandbox Code Playgroud)
替代脚本版本:
这是从dig's
输出打印 AUTHORITY 部分的脚本的替代版本。这可能比+short
版本更好,更可靠。注意:这使用8.8.8.8
,这是谷歌的公共 DNS。如果您觉得有必要,请使用不同的服务器。
$ xargs -L1 --arg-file=ip-addr.txt sh -c 'printf "%s: " "$1"; dig +short -x "$1"' sh
8.8.8.8: google-public-dns-a.google.com.
208.67.220.220: resolver2.opendns.com.
Run Code Online (Sandbox Code Playgroud)
演示:
$ cat ip_addresses.txt | xargs ./reverse_dns_lookup.sh
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 -x 8.8.8.8 +noall +authority +answer
; (1 server found)
;; global options: +cmd
8.8.8.8.in-addr.arpa. 21390 IN PTR google-public-dns-a.google.com.
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 -x 208.67.220.220 +noall +authority +answer
; (1 server found)
;; global options: +cmd
220.220.67.208.in-addr.arpa. 6674 IN PTR resolver2.opendns.com.
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 -x 192.30.253.112 +noall +authority +answer
; (1 server found)
;; global options: +cmd
253.30.192.in-addr.arpa. 10 IN SOA ns1.p16.dynect.net. ops.github.com. 6 3600 600 604800 60
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14664 次 |
最近记录: |