-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
86 lines (73 loc) · 1.65 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/cxjava/gscan"
)
var (
logger *log.Logger
cdnChan = make(chan string, 10)
fastest = ""
addr = flag.String("a", ":8888", "The proxy listen address")
queryURL = flag.String("q", "/otn/leftTicket/query", "The prefix of 12306 query URL")
size = flag.Int("s", 20, "The fastest number of IP")
)
func init() {
go addCDN()
logger = log.New(os.Stdout, "[AutoChange12306CDN]", log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile)
}
func addCDN() {
fastestCDN := make(map[string]string, *size)
ips := gscan.ScanIP("./iprange.conf", gscanConf)
fastest = ips[0] + ":443"
t := 0
for _, v := range ips {
if t >= *size {
break
}
t++
fastestCDN[v] = v + ":443"
fmt.Println(v)
}
logger.Println("CDN query is done! fastest one is:" + fastest)
logger.Println("Server is listening at ", *addr)
go func() {
for {
for _, v := range fastestCDN {
cdnChan <- v
}
}
}()
}
func main() {
flag.Parse()
ch := make(chan bool)
Gomitmproxy(*addr, ch)
<-ch
}
var gscanConf = `
{
"ScanWorker" : 40,
"VerifyPing": false,
"ScanMinPingRTT" : 5,
"ScanMaxPingRTT" : 1000,
"ScanMinSSLRTT": 0,
"ScanMaxSSLRTT": 3000,
"ScanCountPerIP" : 2,
"Operation" : "ScanGoogleIP",
"ScanGoogleIP" :{
"SSLCertVerifyHosts" : ["kyfw.12306.cn"],
"HTTPVerifyHosts" : ["kyfw.12306.cn"],
"RecordLimit" : 500,
"OutputSeparator": "\",\r\n\"",
"OutputFile" : "./12306_ip.txt"
},
"ScanGoogleHosts":{
"InputHosts":"./hosts.input",
"OutputHosts": "./hosts.output",
"HTTPVerifyHosts" : ["www.google.com"]
}
}
`