-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
select.sh
executable file
·123 lines (117 loc) · 2.92 KB
/
select.sh
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
#!/usr/bin/env bash
#
# 从output内的IP里选择除最优的IP, 并调用use.sh和dnsmasq.sh
#
# EP:
# $ ./select.sh
#
# Author: [email protected]
#
if [ ! -d output ]
then
echo "no output directory.";
exit 0;
fi
domains="
*.google.com
accounts.google.com
checkout.google.com
adwords.google.com
mail.google.com
*.mail.google.com
*.googleusercontent.com
*.gstatic.com
*.googleapis.com
*.appspot.com
*.googlecode.com
*.google-analytics.com
ssl.google-analytics.com
"
>../google.dnsmasq.conf
filter_data=/tmp/filter.sh.data
for domain in $domains
do
./filter.sh $domain > $filter_data
_ip=""
line=""
while read line
do
ip=$(echo $line | awk '{print $1}')
c=$(nmap --host-timeout 2s $ip -p 443 2>/dev/null | grep -Pc "443/tcp open")
if [ $c -ne 1 ]
then
continue
fi
if [ $(uname) = "Darwin" ]
then
cer=$(wget https://$ip 2>&1 | grep "common name" | grep -Po "'\S*'" |head -1|cut -d \' -f 2)
else
cer=$(curl https://$ip 2>&1 | grep -Po "'\S*'" |head -1|cut -d \' -f 2)
fi
if [ "$cer" != $domain ]
then
continue
fi
if [ $domain = "*.google.com" ]
then
#c=$(echo $ip | grep -Pc "^(173|207|209|216|64|66|72|74)")
c=$(echo $ip | grep -Pc "^(173|207|209|66|72|74)")
if [ $c -ne 1 ]
then
continue
fi
c=$(nmap --host-timeout 9s $ip -p 5222 2>/dev/null | grep -Pc "5222/tcp open")
if [ $c -eq 1 ]
then
continue
fi
fi
_ip=$ip
break
done < $filter_data
if [ -z "$line" ]
then
echo "[WARNING] $domain"
continue
fi
if [ -z "$_ip" ]
then
echo "[WARNING] $domain"
continue
fi
echo $line
./use.sh $domain $ip
if [ $domain != "*.mail.google.com" ]
then
./dnsmasq.sh $(echo $domain | sed -r "s/\*\.//") $ip
fi
# extra
if [ $domain = "*.googleusercontent.com" ]
then
./use.sh *.ggpht.com $ip
./dnsmasq.sh ggpht.com $ip
elif [ $domain = "*.googleapis.com" ]
then
./use.sh googleapis.com $ip
./use.sh talkgadget.google.com $ip
./use.sh *.talkgadget.google.com $ip
./dnsmasq.sh talkgadget.google.com $ip
elif [ $domain = "*.appspot.com" ]
then
./use.sh appspot.com $ip
elif [ $domain = "*.mail.google.com" ]
then
for host in $(grep -P "\w+\.mail\.google\.com" hosts.all | awk '{print $2}')
do
./dnsmasq.sh $host $ip
done
elif [ $domain = "*.google.com" ]
then
./use.sh google.com $ip
for host in $(grep -P -A 9999 "OTHERS$" hosts.all | awk '{print $2}')
do
./use.sh $host $ip
./dnsmasq.sh $host $ip
done
fi
done