host + whois找出某網站的資訊

for....do.....done迴圈

執行以下命令

ip=host tw.yahoo.com | grep 'address' | head -1 | awk '{ print $4}'
whois $ip

編寫shell

#!/bin/bash
#取得所有參數
domarg=$@
[ $# -eq 0 ] && { echo "使用: $0 domain1.xxx domain2.xxx ..."; exit 1; }
for dom in $domarg
do
        echo "--------------- $dom 的資訊----------------"
        echo ""
        ip=$(host $dom | grep 'address' | head -1 | awk '{ print $4}')
        [ "$ip" == "" ] && { echo "Error: $dom 不存在或dns解析有誤 ."; continue; }
        echo "取得資訊中....=>$dom [ $ip ]"
        whois "$ip" 
        echo "----------------end-----------------"
done 

./domaininfo kawsing.gitbook.io tw.yahoo.com www.google.com

Last updated