-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (58 loc) · 2.93 KB
/
main.go
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
package main
import (
"fmt"
"github.com/anaskhan96/soup"
"log"
"time"
)
func fetch(key string, url string, ch chan bool) {
soup.Headers = map[string]string{
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36",
}
source, err := soup.Get(url)
if err != nil {
log.Fatal(err)
}
doc := soup.HTMLParse(source)
ip := doc.Find("ul", "class", "comma-separated").Find("li").Text()
if ip != "" {
fmt.Println(ip + " " + key)
}
time.Sleep(2 * time.Second)
ch <- true
}
func main() {
urls := map[string]string{
"github.com": "https://github.com.ipaddress.com",
"gist.github.com": "https://github.com.ipaddress.com/gist.github.com",
"assets-cdn.github.com": "https://github.com.ipaddress.com/assets-cdn.github.com",
"spotlights-feed.github.com": "https://github.com.ipaddress.com/spotlights-feed.github.com",
"raw.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/raw.githubusercontent.com",
"gist.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/gist.githubusercontent.com",
"cloud.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/cloud.githubusercontent.com",
"camo.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/camo.githubusercontent.com",
"avatars.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars0.githubusercontent.com",
"avatars0.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars0.githubusercontent.com",
"avatars1.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars1.githubusercontent.com",
"avatars2.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars2.githubusercontent.com",
"avatars3.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars3.githubusercontent.com",
"avatars4.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars4.githubusercontent.com",
"avatars5.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars5.githubusercontent.com",
"avatars6.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars6.githubusercontent.com",
"avatars7.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars7.githubusercontent.com",
"avatars8.githubusercontent.com": "https://githubusercontent.com.ipaddress.com/avatars8.githubusercontent.com",
}
fmt.Println("正在输出结果,请稍等:")
ch := make(chan bool)
for key, url := range urls {
go fetch(key, url, ch)
}
for range urls {
<-ch
}
fmt.Println("输出结果完毕,请复制粘贴到hosts文件。")
fmt.Println("Mac系统和Linux系统hosts文件位置:/etc/hosts")
fmt.Println("Win系统hosts文件位置:c:/windows/system32/drivers/etc/hosts")
// 防止windows下立刻退出
time.Sleep(60 * time.Second)
}