追加読書

追加読書

ドメインリストでメールサーバーのIPアドレスを確認して、IPアドレスと一致することを確認する必要があります。具体的には:

  1. 照会するドメインのリストを作成する
  2. ドメイン別MXレコードの発掘
  3. IPアドレスMXレコードクエリ結果のAレコードマイニング
  4. IPが特定のIPと一致する場合は、「はい」または「いいえ」を返します。

ステップ3で詰まった。

これまで私のスクリプトの関連部分は次のとおりです。

#!/bin/bash
# Bulk DNS Lookup
#
# File name/path of domain list:
domain_list='domains.txt' # One FQDN per line in file.

# File name of output text
output='ns_output.txt'

# Clears previous output
> $output

# IP address of the nameserver used for lookups:
ns_ip='192.168.250.67'
#
# Seconds to wait between lookups:
loop_wait='1' # Is set to 1 second.

for domain in `cat $domain_list` # Start looping through domains
do
    echo $domain "Mail servers" >> $output
    MX=$(dig @$ns_ip MX $domain +short) #query MX records from domain list and store it as varial $MX
    echo $MX >> $output;
    echo " " >> $output
    echo " " >> $output
    sleep $loop_wait # Pause before the next lookup to avoid flooding NS
done;

問題は、別のAレコードマイニングを実行できるように出力を変数に変換する方法がわからないことです。

c****s.com Name Servers
c****s.com. 14400 IN NS ns1.a****l.com. yes

c****s.com Mail servers
10 mail.c*****s.com. 20 mail2.c****s.com.

MXクエリから返された各サーバーのIPアドレスを返すために結果をクエリする方法はありますか?

編集:私はすべての人の答えを試してみましたが、それはすべてうまくいきましたが、Gilesが実装するのが最も簡単であることがわかりました。これが私の最終コードです。

    MX=$(dig @$ns_ip MX $domain +short) #query MX records from domain list and store it as variable $MX
    arr=( $MX ) #creates array variable for the MX record answers
    for ((i=1; i<${#arr[@]}; i+=2)); #since MX records have multiple answers, for loop goes through each answer
      do
        echo ${arr[i]} >> $output; #outputs each A record from above MX dig
        dig A +short "${arr[i]}" >> $output #queries A record for IP and writes answer
        MX_IP=$(dig A +short "${arr[i]}") #sets IP address from the dig to variable MX_IP
        if [[ "${arr[i]}" == *"a****d"* ]] #if the mail server host name contains a***d
          then
            echo "yes - spam filter" >> $output
          else
          if [[ $MX_IP == $CHECK_IP ]] #if not, check to see if the mail server's IP matches ours.
            then
              echo "yes - mail server"  >> $output
            else
              echo "no" >> $output
          fi
        fi

以下はサンプル出力です(編集用に検閲されたドメイン名とIP)。

a***l.com Mail servers  lastmx.a****d.net. 
85.x.x.x 
209.x.x.x
95.x.x.x yes - spamfilter
....
mail.b***c.com.
72.x.x.x yes - mail server

backup.b***c.com.
50.x.x.x no

mail2.b***c.com.
50.x.x.x no

ベストアンサー1

行く方法:

arr=( $MX )
for ((i=1; i<${#arr[@]}; i+=2)); do dig A +short "${arr[i]}"; done

 出力:

108.177.15.26
209.85.233.27
172.253.118.27
108.177.97.26
173.194.202.26

おすすめ記事