-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
getip.sh
executable file
·41 lines (37 loc) · 1.08 KB
/
getip.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
#!/usr/bin/env bash
#
# 此会遍历hosts.do里面的域名并查询dns解析出的IP(如果域名前面已经写有IP则跳过查询)
# 此脚本并不会检查解析到的IP是否被GFW封锁或封锁443端口, 可移步find.sh查询
#
# Author: [email protected]
#
# YouTube IP: http:https://compnetworking.about.com/od/traceipaddresses/f/youtube-ip-addr.htm
function getip(){
times=0;
until [ `echo $ip | grep -Pc "^(173|60|74|208|4)"` -eq 1 ]
do
ip=$(dig +tcp $1 @208.67.220.220 | grep -P 'IN\s+?A'| tail -1 | awk '{printf("%s", $5)}')
times=$(($times+1))
if [ $times -eq 20 ]
then
break
fi
done
echo -n $ip;
}
for host in $(cat hosts.do | awk '{if($2) printf("%s\n", $2); else printf("%s\n", $1);}')
do
ip=$(grep -P "$host" hosts.do | awk "{if(\$2==\"$host\") printf(\"%s\", \$1);}")
if [ -z $ip ]
then
ip=$(getip $host)
fi
if [ -z $ip ]
then
echo "[WARNING] $host"
continue;
fi
output="$ip $host"
echo $output
sed -i -r "s/.*? $host/$output/" hosts.all
done