-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_domain.txt
172 lines (158 loc) · 5.26 KB
/
check_domain.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
if [ "$1" == "-h" ]; then
cat <<EOF
*****************************************************************
* This is my study script
* Power by Lex. Let's go! and be happy!
* version 1.0
echo "Examples:"
only ./${0##*/}
*****************************************************************
EOF
exit 0
fi
SCRIPT_NAME="${0##*/}"
info() {
echo "${SCRIPT_NAME}: ${1}"
}
warn() {
info "[WARNING]: ${1}" >&2
}
fatal() {
warn "ERROR: ${1}"
exit 2
}
# define domain list
finish() {
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "ERROR: failed your command."
fi
}
domain_ip=/tmp/a.txt
collect_ip=/tmp/b.txt
# Specify DNS server
dnsserver="119.29.29.29"
# function to get IP address
function get_ipaddr {
local hostname=$1
local query_type=A
ip_address=""
# use host command for DNS lookup operations
host -t ${query_type} "${hostname}" ${dnsserver} &>/dev/null
if [ "$?" -eq "0" ]; then
# get ip address
ip_address="$(host -t ${query_type} "${hostname}" ${dnsserver} | awk '/has.*address/{print $NF; exit}')"
else
echo "############"
fi
# display ip
echo "$ip_address"
}
true >$collect_ip
#cat /home/lex/dns/a.txt| while IFS=" " read -r line;do domain_array+=("$line");done
# The next ok and for loop
#domain_array=($(awk '{print$1}' <$domain_ip))
# If the output should be a single element: SC2207 the next ok .but slow
#domain_array=("$(awk '{print$1}' <$domain_ip)")
# The next ok but not loop
#IFS=" " read -r -a domain_array <<< "$(cat $domain_ip|awk '{print$1}')"
#echo "${domain_array[@]}"
awk 'BEGIN{while (a++<50) s=s "-"; print s,"testing output only one",s}'
IFS=' ' read -r -a domain_array <<< "$(cat < $domain_ip|awk '{print$1}')"
echo "${domain_array[@]}"
awk 'BEGIN{while (a++<50) s=s "-"; print s,"testing output finished",s}'
awk 'BEGIN{while (a++<50) s=s "-"; print s,"testing read from file",s}'
IFS=' '
while read -r domain_array ip_array;do
echo "domain_array is ${domain_array}"
get_ipaddr "${domain_array}"
echo "${domain_array}" "$(get_ipaddr "${domain_array[$i]}")" >>$collect_ip
echo "ip_array is ${ip_array}"
done < $domain_ip
awk 'BEGIN{while (a++<50) s=s "-"; print s,"get_ipaddr and collect ip finished",s}'
cat $collect_ip
# the next old ,but's ok
#domain_array=($(awk '{print$1}' <$domain_ip))#
#for ((i = 0; i < ${#domain_array[@]}; i++)); do
# echo -e "\033[31m ${domain_array[$i]} \033[0m"
# #echo ${domain_array[$i]}
# get_ipaddr "${domain_array[$i]}"
# echo "${domain_array[$i]}" "$(get_ipaddr "${domain_array[$i]}")" >>$collect_ip
#done
awk 'BEGIN{while (a++<50) s=s "-"; print s,"分割线",s}'
echo "now begin compare file"
function checkfilesume() {
local_file_sum=$(md5sum $domain_ip | cut -d" " -f1)
gener_file_sum=$(md5sum $collect_ip | cut -d" " -f1)
if [ "$local_file_sum" == "$gener_file_sum" ]; then
echo "checksum success"
else
echo "checksum failure"
fi
}
#checkfilesume
awk 'BEGIN{while (a++<50) s=s "-"; print s,"diff file",s}'
true >/tmp/c.txt
diff /tmp/a.txt /tmp/b.txt
#sdiff /tmp/a.txt /tmp/b.txt
#sdiff /tmp/a.txt /tmp/b.txt|grep "|"
if [ $? -eq 0 ]; then
echo "compare record successfully"
echo "the next will exit this script"
exit
else
echo "Because The result different . next I will testing request domain and ip"
awk 'BEGIN{while (a++<50) s=s "-"; print s,"will generate c.txt",s}'
#sdiff /tmp/a.txt /tmp/b.txt|grep "|" > /tmp/c.txt
#cat /tmp/c.txt|while IFS=" " read -r line;do domain_array+=("$line");done
# 对旧的记录进行再次检查,看是否能够访问,所以过滤的 <
#diff /tmp/a.txt /tmp/b.txt|grep "<"|awk '{print$2}' > /tmp/c.txt
diff /tmp/a.txt /tmp/b.txt | grep "<" | awk '{for(i=2;i<=NF;i++){printf "%s ", $i}; printf "\n"}' >/tmp/c.txt
diff_ip=/tmp/c.txt
if [ -s "$diff_ip" ]; then
echo " the diff ip"
awk 'BEGIN{while (a++<50) s=s "-"; print s,"testing request domian ip ",s}'
IFS=' '
while read -r domain ip; do
echo "domain: $domain"
echo "ip: $ip"
echo "-----------------------------"
echo "$domain $ip"
#stat=$(/usr/bin/curl -o /dev/null -s -w %{http_code} https://$ip -H "Host:$domain" -k)
stat=$(/usr/bin/curl -o /dev/null -s -w %'{http_code}' https://"$ip" -H "Host:$domain" -k)
echo "$stat"
if [ "$stat" -eq 200 ]; then
echo "The metadata is available. we will house keep /tmp/c.txt"
sed -i.bak "/$domain/d" /tmp/c.txt
else
echo "The metadata is unavailable. keep file /tmp/c.txt"
echo "So next we need keep Checking The /tmp/c.txt"
fi
done <$diff_ip
else
echo "no diff ip all of ok .Don't worry . GoodBye"
fi
fi
awk 'BEGIN{while (a++<50) s=s "-"; print s,"request finished , keep checking the /tmp/c.txt",s}'
if [ -s /tmp/c.txt ]; then
echo "will warning"
else
echo "no warning"
fi
: <<EOF
#
#cat /tmp/a.txt
www.baidu.com 14.215.177.39
www.sohu.com 119.96.200.204
diff /tmp/a.txt /tmp/b.txt
1c1
< www.baidu.com 14.215.177.39
---
> www.baidu.com 14.215.177.38 这个是收集到的IP地址
➜ shell diff /tmp/a.txt /tmp/c.txt
➜ shell echo $?
0
➜ shell cat /tmp/c.txt
www.baidu.com 14.215.177.39,14.215.177.38
EOF