在具有输出的终端上运行批处理DNS + Whois搜索 [英] Run Batch DNS + Whois Search on Terminal with Output

查看:83
本文介绍了在具有输出的终端上运行批处理DNS + Whois搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些DNS记录搜索的批处理搜索与我的终端上的Whois搜索结合在一起.我有一个包含域列表的CSV文件,我想运行以下批处理搜索器:

  • MX搜索:host -t mx $domain
  • NS搜索:host -t ns $domain

这很容易.

使用Whois搜索将其合并;它只返回某些Whois数据的摘要;我需要在whois服务器中查询域名,如下所示: Whois

我可以使用-h来仅记录域注册人详细信息,例如电话,国家/地区代码等.

  • 怀俄明州: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是下面显示的注册人数据;

示例预期输出屏幕抓取

谢谢.

解决方案

您已经知道不同的域指向不同的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数据中抓取,上面的脚本应该向您显示如何对列表中的每个域执行此操作.

I am trying to combine a batch search for some DNS records search with Whois search on my terminal. I have a CSV file with a list of domains and I would like to run the following batch searchers:

  • MX search: host -t mx $domain
  • NS search: host -t ns $domain

This are pretty easy.

Combine this with Whois Search ; Which returns only a summary of some of the Whois data;I would need to query the whois server for the domain which is fine like: whois

I can use -h, to only record Domain Registrant Details such as Telephone, Country code etc. I have tried this:

  • Whois: whois -h 'Registrar WHOIS Server:' "domain" Which gives me the output as well for only Registrant details.

So when I combine all into a single bash file, I get:

#!/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"

I would love to get a CSV output with the domain, mx (only 1), NS (only 1), whois whois is registrant data s shown below;

Sample Expected Output Screengrab

Thank you.

解决方案

You already know that different domains point to different whois servers. I think you are going to find that each registrar has their own favourite way of presenting information via whois, and that they are not consistent. ICANN mandates that a minimum set of data be available via whois, but some of the data you're looking for may fall outside that set.

The following strips just basic data from whois.internic.net, which you can use for gathering DNS servers, whois servers and 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

If you really want to try to scrape from the whois data at $whois, the script above should show you how you might be able to do that for each domain in your list.

这篇关于在具有输出的终端上运行批处理DNS + Whois搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆