-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiplookup.sh
More file actions
executable file
·96 lines (73 loc) · 2.08 KB
/
Copy pathiplookup.sh
File metadata and controls
executable file
·96 lines (73 loc) · 2.08 KB
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
#!/usr/bin/env bash
hosts=/etc/hosts
iplookup(){
IP=$(dig +short $1 | head -n 1)
echo ${IP}
}
domains=(
"github.githubassets.com"
"central.github.com"
"desktop.githubusercontent.com"
"assets-cdn.github.com"
"camo.githubusercontent.com"
"github.map.fastly.net"
"github.global.ssl.fastly.net"
"gist.github.com"
"github.io"
"github.com"
"api.github.com"
"raw.githubusercontent.com"
"user-images.githubusercontent.com"
"favicons.githubusercontent.com"
"avatars5.githubusercontent.com"
"avatars4.githubusercontent.com"
"avatars3.githubusercontent.com"
"avatars2.githubusercontent.com"
"avatars1.githubusercontent.com"
"avatars0.githubusercontent.com"
"avatars.githubusercontent.com"
"codeload.github.com"
"github-cloud.s3.amazonaws.com"
"github-com.s3.amazonaws.com"
"github-production-release-asset-2e65be.s3.amazonaws.com"
"github-production-user-asset-6210df.s3.amazonaws.com"
"github-production-repository-file-5c1aeb.s3.amazonaws.com"
"githubstatus.com"
"github.community"
"media.githubusercontent.com"
)
domains_bak=(
"github.com"
"github.global.ssl.fastly.net"
"raw.githubusercontent.com"
)
printf "##########dig short domain start############\n"
IpAddress+="# MyAuto $(date)\n$(
for domain in "${domains[@]}"; do
{
ipaddress=$(iplookup $domain)
if [[ -n "$ipaddress" ]]; then
printf "$ipaddress $domain\n"
else
printf "# $domain not found!\n"
fi
} &
done
wait
)\n# MyAuto on $(date)\n"
printf "ok edit hosts ... \n"
if [ "$EUID" -ne 0 ]; then
printf "error\nwill write\n$IpAddress\nPlease run as root"
else
OS="`uname`"
if [[ "$OS" == "darwin"* ]]; then
sed -i '' -e '/^# MyAuto.*/,/&/d' $hosts
else
sed -i -e '/^# MyAuto.*/,/&/d' $hosts
fi
printf "$IpAddress" >>$hosts
printf "ok\n"
# 清除DNS缓存命令
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder;say flushed
printf "Reload OK!\n"
fi