bash - 在终端上运行批量 DNS + Whois 搜索并输出
问题描述
我正在尝试将一些 DNS 记录搜索的批量搜索与我的终端上的 Whois 搜索结合起来。我有一个包含域列表的 CSV 文件,我想运行以下批处理搜索器:
- MX 搜索:
host -t mx $domain
- NS搜索:
host -t ns $domain
这很容易。
将此与 Whois 搜索结合使用;它只返回一些 Whois 数据的摘要;我需要查询 whois 服务器的域,这很好:whois
我可以使用-h
, 只记录域名注册人的详细信息,例如电话、国家代码等。我试过这个:
- Whois:
whois -h 'Registrar WHOIS Server:' "domain"
这也为我提供了仅注册人详细信息的输出。
因此,当我将所有内容合并到一个 bash 文件中时,我得到:
#!/usr/bin/env bash
file="${1:-input_test1.csv}"
if [[ ! -f "$file" ]]; then
printf 'No file: %s\n' "$file" >&2
exit 1
fi
(
read -r header; printf '%s\n' "$header"
while IFS=, read -r domain; do
mx="$(host -t mx "$domain" | sort | head -1)"
ns="$(host -t ns "$domain" | sort| head -1)"
whois="$(whois -h "$(whois" "$domain" | grep 'Registrar WHOIS Server:') "$domain")
printf '%s,"%s"\n' "$domain" "$mx" "$ns" "$whois"
done
) < "$file"
我很想得到一个带有域的 CSV 输出,mx(只有 1 个),NS(只有 1 个),whois whois is registrant data 如下所示;
谢谢你。
解决方案
您已经知道不同的域指向不同的 whois 服务器。我想您会发现每个注册商都有自己喜欢的通过 whois 呈现信息的方式,而且它们并不一致。ICANN 要求通过 whois 提供最少的数据集,但您要查找的某些数据可能不属于该集。
以下仅从 whois.internic.net 中删除基本数据,您可以使用这些数据来收集 DNS 服务器、whois 服务器和 MX:
#!/usr/bin/env bash
mapfile -t domains < domains.lst
declare -i i
for this in "${domains[@]}"; do
unset a; declare -A a=()
unset ns; declare -a ns=()
whois=""
i=0
while IFS=: read -r key value; do
#printf "key=%s / value=%s\n" "$key" "$value"
case "$key" in
*"Registrar WHOIS Server") whois="${value## }" ;;
*"Name Server") ns+=("${value## }") ;;
esac
done < <(whois -h whois.internic.net "$this")
read mx < <(host -t mx "$this" | sort | awk 'NR==1{print $NF}')
printf '%s,%s,%s,%s\n' \
"$this" \
"$mx" \
"$whois" \
"$(printf '%s ' "${ns[@]}")"
done
如果您真的想尝试从 中的 whois 数据中抓取$whois
,上面的脚本应该向您展示如何为列表中的每个域执行此操作。
推荐阅读
- java - 我如何在 Fragment 上初始化 BluetoothConnectionService
- elasticsearch - 如何配置filebeat和logstash?3 台虚拟机
- python - 如何编写循环直到(Python Anaconda)
- python - 将 lambda 字符串转换为 lambda 函数签名
- python - Pyspark - 将时间戳传递给 udf
- javascript - setInterval 内的关闭计数器
- mongodb - mongodb查询具有未知属性的第三级
- ios - IOS:从另一个没有 URL 架构的应用程序打开一个应用程序
- ruby-on-rails - Shopify 应用的 Heroku 服务器超时
- unity3d - 输入字段以错误的格式粘贴阿拉伯文本