2014-02-06 142 views
0

我遇到了腳本問題。 在我的工作中,我經常需要檢查域名,MX記錄和類似數據的PTR。我做過的最劇本的,但是當我做這樣的事情
這是子域如何區分域名與子域名

e-learning.go4progress.pl 

這是域名,但第二級出現的問題?

simple.com.pl 

現在,在我的劇本有這樣的:如果我不把WWW,它增加了和做

dig www.e-learning.go4progress.pl 
dig e-learning.go4progress.pl 
dig go4progress.pl 

他計數點和減1,但問題是,當域看起來像

simple.com.pl 

因爲劇本讓挖過的

com.pl 

我不檢查包含com.pl,co.uk,gov.pl的許多域。我有一個想法,使數組和比較這是我放在腳本與數組,當它發現在數組的字符串組件,他減去2而不是1;) 我粘貼腳本的一部分,以更好地瞭解我爲什麼他substracks 1 。

url="`echo $1 | sed 's~http[s]*://~~g' | sed 's./$..' | awk '!/^www/ {$0="www." $0}1'`" 
ii=1 
dots="`echo $url | grep -o "\." | wc -l`" 
while [ $ii -le $dots] ; do 
     cut="`echo $url | cut -d "." -f$ii-9`" 
     ip="`dig +short $cut`" 
     host="`dig -x $ip +short`" 
     if [[ -z "$host" ]]; then 
       host="No PTR" 
     fi 
     echo "strona: $cut Host: $host" 
     ii=$[ii + 1] 

也許你有不同的想法如何幫助我的問題。

第二個問題是如何區分域和子域。
我需要比較子域的mx記錄(當url包含子域時)和mx記錄頂級域。
我等待着你的迴應;)

+0

幾天,我回答有人用類似的請求,先審查它http://stackoverflow.com/questions/21440409/extract-parent-domain-name-from-a-list-of-url-through-bash-shellscripting – BMW

+0

嗨,謝謝你的線索;) – Bolo92

回答

0

我的解決方案,以找到與註冊商註冊的域名:前

wget https://raw.githubusercontent.com/gavingmiller/second-level-domains/master/SLDs.csv 

DOMAIN="www.e-learning.go4progress.co.uk"; 
KEEPPARTS=2; 
TWOLEVELS=$(/bin/echo "${DOMAIN}" | /usr/bin/rev | /usr/bin/cut -d "." --output-delimiter=".\\" -f 1-2 | /usr/bin/rev); 
if /bin/grep -P ",\.${TWOLEVELS}" SLDs.csv >/dev/null; then 
    KEEPPARTS=3; 
fi 
DOMAIN=$(/bin/echo "${DOMAIN}" | /usr/bin/rev | /usr/bin/cut -d "." -f "1-${KEEPPARTS}" | /usr/bin/rev); 
echo "${DOMAIN}" 

感謝https://github.com/gavingmiller/second-level-domainshttps://github.com/medialize/URI.js/issues/17#issuecomment-3976617