| 1 |
#!/bin/bash |
| 2 |
set -e |
| 3 |
|
| 4 |
debug=1 |
| 5 |
|
| 6 |
ehlo=pro5s2.nethence.com |
| 7 |
#ehlo=`curl -s ip.nethence.com | sed -n 1p | awk '{print $NF}' | sed 's/\.$//'` |
| 8 |
echo using $ehlo as EHLO |
| 9 |
|
| 10 |
sep="sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'" |
| 11 |
|
| 12 |
function checkmx { |
| 13 |
#so far we only take first MX without attemping to query DANE for backup ones |
| 14 |
primary=`host -4 -t MX $domain | sort --numeric-sort | head -1 | awk '{print $NF}'` |
| 15 |
primary=${primary%\.} |
| 16 |
|
| 17 |
#has no MX record |
| 18 |
if [[ $primary = record ]]; then |
| 19 |
(( debug == 1 )) && echo -e $domain\\tnomx |
| 20 |
elif [[ $primary = "3(NXDOMAIN)" ]]; then |
| 21 |
(( debug == 1 )) && echo -e $domain\\tnxdomain |
| 22 |
elif [[ $primary = "2(SERVFAIL)" ]]; then |
| 23 |
(( debug == 1 )) && echo -e $domain\\tservfail |
| 24 |
#;; connection timed out; no servers could be reached |
| 25 |
elif [[ $primary = "reached" ]]; then |
| 26 |
(( debug == 1 )) && echo -e $domain\\ttimeout |
| 27 |
elif [[ $domain = $primary ]]; then |
| 28 |
echo -e $domain\\tmx $primary equals-mx |
| 29 |
else |
| 30 |
ip=`host $domain | awk '{print $NF}'` |
| 31 |
primaryip=`host $primary | awk '{print $NF}'` |
| 32 |
if [[ $ip = $primaryip ]]; then |
| 33 |
echo -e $domain\\tmx $primary but-same-ip |
| 34 |
else |
| 35 |
echo -e $domain\\tmx $primary |
| 36 |
fi |
| 37 |
unset ip primaryip |
| 38 |
fi |
| 39 |
unset primary |
| 40 |
} |
| 41 |
|
| 42 |
function parselist { |
| 43 |
[[ -z $1 ]] && echo error function $0 requires file argument && exit 1 |
| 44 |
[[ ! -r $1 ]] && echo error function $0 cannot read file $1 && exit 1 |
| 45 |
|
| 46 |
echo writing to $1.mx ... |
| 47 |
for domain in `cat $1`; do |
| 48 |
checkmx |
| 49 |
done > $1.mx && echo wrote to $1.mx; unset domain |
| 50 |
} |
| 51 |
|
| 52 |
echo -n entering domains/mx/ ... |
| 53 |
mkdir -p domains/mx/ |
| 54 |
cd domains/mx/ && echo done |
| 55 |
|
| 56 |
echo -n splitting ptr.unique.nomadness.unique into 22 files... |
| 57 |
split -a2 -d -nl/22 ../domains.unique domains.unique && echo done |
| 58 |
|
| 59 |
#TODO also check PTR FQDNs ptr.unique.nomadness[0-9][0-9] |
| 60 |
#for input in ptr.unique.nomadness06.domains; do |
| 61 |
#for input in domains.unique[0-9][0-9]; do |
| 62 |
for input in domains.unique.moar; do |
| 63 |
parselist $input & |
| 64 |
done; unset input |
| 65 |
jobs |
| 66 |
cat <<EOF |
| 67 |
|
| 68 |
watch with |
| 69 |
|
| 70 |
ps auxfww | grep checkmx |
| 71 |
tail -F domains/mx/*.mx |
| 72 |
watch ls -lF domains/mx/*.mx |
| 73 |
|
| 74 |
EOF |
| 75 |
time wait |
| 76 |
|
| 77 |
echo -n merging defined MX from \*.mx into mx ... |
| 78 |
cut -f2 *.mx | grep -E '^mx ' | awk '{print $2}' > mx && echo done |
| 79 |
wc -l mx | eval $sep |
| 80 |
|
| 81 |
#used fix on first shot (we did not use 'mx ' for equals and sameip) |
| 82 |
#grep --no-filename equals-mx$ *.mx | awk '{print $1}' > mx.equals-mx |
| 83 |
#grep --no-filename but-same-ip$ *.mx | awk '{print $2}' > mx.but-same-ip |
| 84 |
#cat mx.equals-mx mx.but-same-ip >> mx |
| 85 |
|
| 86 |
echo -n unique into mx.unique ... |
| 87 |
sort --version-sort -u mx > mx.unique && echo done |
| 88 |
wc -l mx.unique | eval $sep |
| 89 |
|
| 90 |
#TODO 2/3rd-level vs all |
| 91 |
|