├── Conf ├── config.go ├── config.ini ├── metaproxy.lst └── proxy.lst ├── JCRandomProxy.exe ├── Proxy ├── AddAProxy.go ├── CheckProxy.go ├── CheckProxySche.go ├── GetAProxy.go ├── GetAProxyA.go ├── GetAProxyB.go └── RemoveAProxy.go ├── ProxyEntry ├── localproxy.go ├── main.go ├── portforward.go └── proxyRequest.go ├── README.md ├── log.txt └── main.go /Conf/config.go: -------------------------------------------------------------------------------- 1 | package Conf 2 | 3 | import ( 4 | "crypto/tls" 5 | "log" 6 | "path/filepath" 7 | 8 | "github.com/go-ini/ini" 9 | ) 10 | 11 | var ( 12 | PPIP string 13 | PPPort string 14 | UseProxyPool bool 15 | CustomProxyFile string 16 | Port string 17 | UseProxy bool 18 | UseHttpsProxy bool 19 | ) 20 | 21 | func InitConfig() { 22 | 23 | confFile, _ := filepath.Abs("Conf/config.ini") 24 | cfg, err := ini.Load(confFile) 25 | if err != nil { 26 | panic(err) 27 | } 28 | log.Println("JCTest", cfg) 29 | UseProxyPool, _ = cfg.Section("main").Key("UseProxypool").Bool() 30 | Port = cfg.Section("main").Key("Port").String() 31 | UseProxy, _ = cfg.Section("main").Key("UseProxy").Bool() 32 | UseHttpsProxy, _ = cfg.Section("main").Key("UseHttpsProxy").Bool() 33 | PPIP = cfg.Section("proxypool").Key("PPIP").String() 34 | PPPort = cfg.Section("proxypool").Key("PPPort").String() 35 | CustomProxyFile, _ = filepath.Abs(cfg.Section("customproxy").Key("CustomProxyFile").String()) 36 | // log.Println(UseHttpsProxy) 37 | 38 | } 39 | 40 | type Cfg struct { 41 | Port *string 42 | Raddr *string 43 | Log *string 44 | Monitor *bool 45 | Tls *bool 46 | } 47 | 48 | type TlsConfig struct { 49 | PrivateKeyFile string 50 | CertFile string 51 | Organization string 52 | CommonName string 53 | ServerTLSConfig *tls.Config 54 | } 55 | 56 | func NewTlsConfig(pk, cert, org, cn string) *TlsConfig { 57 | return &TlsConfig{ 58 | PrivateKeyFile: pk, 59 | CertFile: cert, 60 | Organization: org, 61 | CommonName: cn, 62 | ServerTLSConfig: &tls.Config{ 63 | CipherSuites: []uint16{ 64 | tls.TLS_RSA_WITH_RC4_128_SHA, 65 | tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, 66 | tls.TLS_RSA_WITH_AES_128_CBC_SHA, 67 | tls.TLS_RSA_WITH_AES_256_CBC_SHA, 68 | tls.TLS_RSA_WITH_AES_128_CBC_SHA256, 69 | tls.TLS_RSA_WITH_AES_128_GCM_SHA256, 70 | tls.TLS_RSA_WITH_AES_256_GCM_SHA384, 71 | tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 72 | tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 73 | tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 74 | tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, 75 | tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, 76 | tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 77 | tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, 78 | tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, 79 | tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, 80 | tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 81 | tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 82 | tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, 83 | tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, 84 | tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, 85 | tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, 86 | tls.TLS_FALLBACK_SCSV, 87 | }, 88 | PreferServerCipherSuites: true, 89 | }, 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Conf/config.ini: -------------------------------------------------------------------------------- 1 | [main] 2 | # 是否使用ProxyPool 3 | UseProxypool = false 4 | # 是否使用自己获取到的代理,与CustomProxyFile配合使用【暂未使用】 5 | UseCustomProxy = true 6 | # 是否使用代理 7 | UseProxy = true 8 | # 是否使用https动态代理 9 | UseHttpsProxy = true 10 | # http代理对外开放的端口 11 | Port = 8081 12 | [proxypool] 13 | # ProxyPool的IP,需要带上http:// 14 | PPIP = http://10.103.91.179 15 | # ProxyPool的端口 16 | PPPort = 5010 17 | [customproxy] 18 | # 放置可用代理的文件 19 | CustomProxyFile = Conf/metaproxy.lst 20 | -------------------------------------------------------------------------------- /Conf/metaproxy.lst: -------------------------------------------------------------------------------- 1 | http,223.82.106.253:3128 2 | http,103.141.182.100:80 3 | http,38.77.36.35:8080 4 | http,54.168.222.142:80 5 | http,211.137.52.159:8080 -------------------------------------------------------------------------------- /Conf/proxy.lst: -------------------------------------------------------------------------------- 1 | http,223.82.106.253:3128 2 | http,103.141.182.100:80 3 | http,38.77.36.35:8080 4 | http,54.168.222.142:80 5 | http,211.137.52.159:8080 -------------------------------------------------------------------------------- /JCRandomProxy.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chroblert/JCRandomProxy/83c6d27b8ff52f9c2711f3586eab6c81f0aee41c/JCRandomProxy.exe -------------------------------------------------------------------------------- /Proxy/AddAProxy.go: -------------------------------------------------------------------------------- 1 | package Proxy 2 | -------------------------------------------------------------------------------- /Proxy/CheckProxy.go: -------------------------------------------------------------------------------- 1 | package Proxy 2 | 3 | import ( 4 | "JCRandomProxy/Conf" 5 | "bufio" 6 | "crypto/md5" 7 | "fmt" 8 | "io/ioutil" 9 | "log" 10 | "net" 11 | "net/http" 12 | "net/url" 13 | "strings" 14 | "time" 15 | ) 16 | 17 | // 验证代理服务器是否可用 18 | func CheckProxy(proxyAddr, checkaddr string) bool { 19 | proxymd5 := fmt.Sprintf("%x", md5.Sum([]byte(proxyAddr))) 20 | // 代理服务器可用,则添加至map中 21 | if CheckProxyA(proxyAddr, checkaddr) { 22 | protocol := strings.Split(proxyAddr, ":")[0] 23 | ip := strings.Split(strings.Split(proxyAddr, "/")[2], ":")[0] 24 | port := strings.Split(proxyAddr, ":")[2] 25 | tmpproxy := aproxy{protocol, ip, port} 26 | // proxylist = append(proxylist, tmpproxy) 27 | proxymap[proxymd5] = tmpproxy 28 | log.Println("当前可用代理池: ", proxymap) 29 | return true 30 | } 31 | // 代理服务器不可用,则删除 32 | delete(proxymap, proxymd5) 33 | delete(metaproxymap, proxymd5) 34 | return false 35 | } 36 | func CheckProxyA(proxyAddr, checkaddr string) bool { 37 | // if !Conf.UseProxyPool { 38 | // return true 39 | // } 40 | 41 | prox, _ := url.Parse(proxyAddr) 42 | log.Println("JCTLog: 代理地址: ", prox.Host) 43 | // Dial and create client connection 44 | proxc, err := net.DialTimeout("tcp", prox.Host, time.Second*5) 45 | if err != nil { 46 | return false 47 | } 48 | // 解析最终目标url 49 | reqURL, err := url.Parse(checkaddr) 50 | if err != nil { 51 | return false 52 | } 53 | log.Println("JCTLog: 目标URL: ", reqURL.String()) 54 | req, err := http.NewRequest(http.MethodGet, reqURL.String(), nil) 55 | if err != nil { 56 | log.Println("JCTLog: http.NewRequest: ", err) 57 | return false 58 | } 59 | 60 | req.Close = false 61 | req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.3") 62 | err = req.Write(proxc) 63 | // log.Println(req) 64 | if err != nil { 65 | log.Println("JCTLog: req.Write: ", err) 66 | return false 67 | } 68 | 69 | resp, err := http.ReadResponse(bufio.NewReader(proxc), req) 70 | if err != nil { 71 | log.Println("JCTLog: http.ReadResponse: ", err) 72 | return false 73 | } 74 | defer resp.Body.Close() 75 | // log.Println("===================sss") 76 | // fmt.Println(resp.Body) 77 | // fmt.Println(resp.StatusCode) 78 | // log.Println(resp.Status) 79 | // fmt.Println(resp.Proto) 80 | // fmt.Println(resp.Header) 81 | 82 | body, err := ioutil.ReadAll(resp.Body) 83 | if err != nil { 84 | log.Println(err) 85 | return false 86 | } 87 | 88 | // fmt.Println(string(body)) 89 | // log.Println("===================eee") 90 | defer resp.Body.Close() 91 | // fmt.Println(strings.Split(prox.Host,":")[1]) 92 | if strings.Contains(string(body), strings.Split(prox.Host, ":")[0]) { 93 | log.Println("包含", prox.Host) 94 | return true 95 | } 96 | // 删除无效代理 97 | if Conf.UseProxyPool { 98 | _, err := http.Get(Conf.PPIP + ":" + Conf.PPPort + "/delete/?proxy=" + prox.Host) 99 | if err != nil { 100 | log.Println(err) 101 | } 102 | // body, err := ioutil.ReadAll(resp.Body) 103 | // if err != nil { 104 | // fmt.Println(err) 105 | // return false 106 | // } 107 | log.Println("JCTLog: 删除代理: ", prox.Host) 108 | } 109 | // if (resp.StatusCode != 200) { 110 | err = fmt.Errorf("Connect server using proxy error,StatusCode [%d]", resp.StatusCode) 111 | return false 112 | // } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /Proxy/CheckProxySche.go: -------------------------------------------------------------------------------- 1 | package Proxy 2 | -------------------------------------------------------------------------------- /Proxy/GetAProxy.go: -------------------------------------------------------------------------------- 1 | package Proxy 2 | 3 | import ( 4 | "JCRandomProxy/Conf" 5 | "math/rand" 6 | ) 7 | 8 | // 定义接收返回的代理的结构体 9 | type ( 10 | PPCount struct { 11 | Count int64 `json:"count"` 12 | } 13 | PP struct { 14 | Check_count int64 `json:"check_count"` 15 | Fail_count int64 `json:"Fail_count"` 16 | Last_status int64 `json:"Last_status"` 17 | Last_time string `json:"last_time"` 18 | Proxy string `json:"proxy"` 19 | Region string `json:"region"` 20 | Source string `json:"source"` 21 | Type string `json:"type"` 22 | } 23 | ) 24 | 25 | type aproxy struct { 26 | protocol string 27 | ip string 28 | port string 29 | } 30 | 31 | var minProxyNum int = 10 32 | var maxProxyNum int = 30 33 | 34 | // var proxylist []aproxy 35 | // 经过验证的可用代理池 36 | var proxymap = make(map[string]aproxy) 37 | 38 | // 从文件中读取的代理 39 | var metaproxymap = make(map[string]aproxy) 40 | 41 | func GetAProxy() (string, string, error) { 42 | // 先判断可用代理池中的可用代理数量是否大于等于10 43 | // 若大于等于10,则从可用代理池中随机取出一个 44 | if len(proxymap) >= 10 { 45 | // tmpProxy := proxylist[rand.Intn(len(proxylist))] 46 | tmpProxy := GetAvailableProxy(proxymap) 47 | return tmpProxy.protocol, tmpProxy.ip + ":" + tmpProxy.port, nil 48 | } 49 | if Conf.UseProxyPool { 50 | return GetAProxyA() 51 | } else { 52 | return GetAProxyB() 53 | } 54 | 55 | } 56 | 57 | // 随机的从可用代理池中取出一个代理 58 | func GetAvailableProxy(tmp map[string]aproxy) aproxy { 59 | keys := make([]string, 0, len(tmp)) 60 | for k := range tmp { 61 | keys = append(keys, k) 62 | } 63 | return tmp[keys[rand.Intn(len(keys))]] 64 | } 65 | -------------------------------------------------------------------------------- /Proxy/GetAProxyA.go: -------------------------------------------------------------------------------- 1 | package Proxy 2 | import ( 3 | "log" 4 | "JCRandomProxy/Conf" 5 | "net/http" 6 | "io/ioutil" 7 | "encoding/json" 8 | ) 9 | func GetAProxyA() (string,string,error){ 10 | // fmt.Println(Conf.PPIP) 11 | ppCountUrl := Conf.PPIP + ":" + Conf.PPPort + "/get_status/" 12 | ppGetUrl := Conf.PPIP + ":" + Conf.PPPort + "/get/" 13 | // 查看当前有多少代理 14 | req, err := http.NewRequest("GET",ppCountUrl,nil) 15 | if err != nil { 16 | log.Println(err) 17 | return "","",err 18 | } 19 | req.Header.Add("accept","application/json") 20 | res,_ := http.DefaultClient.Do(req) 21 | resbody,_ := ioutil.ReadAll(res.Body) 22 | // 解析json数据 23 | ppCount := &PPCount{} 24 | err = json.Unmarshal([]byte(resbody),ppCount) 25 | if err != nil { 26 | log.Println("error: ",err) 27 | return "","",err 28 | } 29 | // 判断是否有可用的代理 30 | if ppCount.Count < 1 { 31 | log.Println("当前没有可用代理") 32 | return "","",err 33 | } 34 | // 获取一个代理 35 | proxy := &PP{} 36 | req, _ = http.NewRequest("GET", ppGetUrl, nil) 37 | req.Header.Add("accept", "application/json") 38 | req.Header.Add("content-type", "application/json") 39 | defer res.Body.Close() 40 | res, _ = http.DefaultClient.Do(req) 41 | resbody, _ = ioutil.ReadAll(res.Body) 42 | err = json.Unmarshal([]byte(resbody), proxy) 43 | if err != nil { 44 | log.Println("error:", err) 45 | return "","",err 46 | } 47 | // 判断代理的类型 48 | var ptype string 49 | if proxy.Type != "" { 50 | ptype = proxy.Type 51 | } else{ 52 | ptype = "http" 53 | } 54 | // 返回 55 | return proxy.Proxy,ptype,err 56 | } -------------------------------------------------------------------------------- /Proxy/GetAProxyB.go: -------------------------------------------------------------------------------- 1 | package Proxy 2 | 3 | import ( 4 | "JCRandomProxy/Conf" 5 | "bufio" 6 | "crypto/md5" 7 | "fmt" 8 | "log" 9 | "math/rand" 10 | "os" 11 | "strings" 12 | "time" 13 | ) 14 | 15 | func GetAProxyB() (string, string, error) { 16 | if len(metaproxymap) != 0 { 17 | tmp := GetAvailableProxy(metaproxymap) 18 | delete(metaproxymap, fmt.Sprintf("%x", md5.Sum([]byte(tmp.protocol+"://"+tmp.ip+":"+tmp.port)))) 19 | return tmp.ip + ":" + tmp.port, tmp.protocol, nil 20 | } 21 | // 设置随机数种子 22 | rand.Seed(time.Now().UnixNano()) 23 | // log.Printf("JCTLog:%s",Conf.CustomProxyFile) 24 | file, err := os.Open(Conf.CustomProxyFile) 25 | if err != nil { 26 | log.Fatal(err) 27 | } 28 | defer file.Close() 29 | // var proxyList []string 30 | scanner := bufio.NewScanner(file) 31 | for scanner.Scan() { 32 | proxystr := scanner.Text() 33 | ptype := strings.Split(proxystr, ",")[0] 34 | proxy := strings.Split(proxystr, ",")[1] 35 | IP := strings.Split(proxy, ":")[0] 36 | Port := strings.Split(proxy, ":")[1] 37 | metaproxymap[fmt.Sprintf("%x", md5.Sum([]byte(ptype+"://"+IP+":"+Port)))] = aproxy{ptype, IP, Port} 38 | // proxyList = append(proxyList, proxystr) 39 | } 40 | // proxystr := proxyList[rand.Intn(len(proxyList))] 41 | // ptype := strings.Split(proxystr, ",")[0] 42 | // proxy := strings.Split(proxystr, ",")[1] 43 | if err := scanner.Err(); err != nil { 44 | log.Fatal(err) 45 | } 46 | // return proxy, ptype, err 47 | tmp := GetAvailableProxy(metaproxymap) 48 | return tmp.ip + ":" + tmp.port, tmp.protocol, nil 49 | } 50 | -------------------------------------------------------------------------------- /Proxy/RemoveAProxy.go: -------------------------------------------------------------------------------- 1 | package Proxy 2 | -------------------------------------------------------------------------------- /ProxyEntry/localproxy.go: -------------------------------------------------------------------------------- 1 | package ProxyEntry 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "log" 7 | "net" 8 | "net/url" 9 | "runtime/debug" 10 | "strings" 11 | ) 12 | 13 | func lproxy(client net.Conn) { 14 | defer func() { 15 | if err := recover(); err != nil { 16 | log.Panic(err) 17 | debug.PrintStack() 18 | } 19 | }() 20 | if client == nil { 21 | return 22 | } 23 | defer client.Close() 24 | 25 | var b [1024]byte 26 | // 读取应用层的所有数据 27 | n, err := client.Read(b[:]) 28 | if err != nil || bytes.IndexByte(b[:], '\n') == -1 { 29 | // 传输层的连接没有应用层的内容,如net.Dial() 30 | log.Println(err) 31 | return 32 | } 33 | var method, host, address string 34 | fmt.Sscanf(string(b[:bytes.IndexByte(b[:], '\n')]), "%s%s", &method, &host) 35 | log.Println(method, host) 36 | hostPortURL, err := url.Parse(host) 37 | if err != nil { 38 | log.Println(err) 39 | return 40 | } 41 | // https 42 | if hostPortURL.Opaque == "443" { 43 | address = hostPortURL.Scheme + ":443" 44 | } else { 45 | // http 46 | if strings.Index(hostPortURL.Host, ":") == -1 { 47 | address = hostPortURL.Host + ":80" 48 | } else { 49 | address = hostPortURL.Host 50 | } 51 | } 52 | // log.Println("JCTLog: hostPortURL", address) 53 | // 建立一个到代理服务器的传输通道 54 | server, err := Dial("tcp", address) 55 | if err != nil { 56 | log.Println("JCTLog: Dial: ", err) 57 | return 58 | } 59 | // 在应用层完成数据转发后,关闭传输层的通道 60 | defer server.Close() 61 | log.Println("JCTLog: server tcp tunnel connection: ", server.LocalAddr().String(), "->", server.RemoteAddr().String()) 62 | 63 | if method == "CONNECT" { 64 | // https 65 | fmt.Fprint(client, "HTTP/1.1 200 Connection Established\r\n\r\n") 66 | } else { 67 | // http 68 | // log.Println("JCTLog: ", "server write ", method) 69 | server.Write(b[:n]) 70 | } 71 | // 进行转发 72 | go func() { 73 | proxyRequest(client, server) 74 | }() 75 | proxyRequest(server, client) 76 | log.Println("JCTLog: 结束: ") 77 | } 78 | 79 | // 建立一个传输通道 80 | // network : 网络类型,tcp 81 | // addr: 最终目标服务器地址 82 | func Dial(network, addr string) (net.Conn, error) { 83 | return net.Dial(network, addr) 84 | } 85 | -------------------------------------------------------------------------------- /ProxyEntry/main.go: -------------------------------------------------------------------------------- 1 | package ProxyEntry 2 | 3 | import ( 4 | "JCRandomProxy/Conf" 5 | "JCRandomProxy/Proxy" 6 | "io" 7 | "log" 8 | "net" 9 | "os" 10 | "runtime/debug" 11 | ) 12 | 13 | /** 14 | * 15 | * Author: JC0o0l 16 | * email: jerryzvs@163.com 17 | * wechat: JC_SecNotes 18 | */ 19 | var mw interface{} 20 | 21 | func init() { 22 | logFile, err := os.OpenFile("log.txt", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666) 23 | if err != nil { 24 | panic(err) 25 | } 26 | mw = io.MultiWriter(os.Stdout, logFile) 27 | log.SetOutput(mw.(io.Writer)) 28 | log.SetFlags(log.LstdFlags | log.Lshortfile) 29 | Conf.InitConfig() 30 | } 31 | 32 | func Proxymain() { 33 | // 监听TCP连接 34 | l, err := net.Listen("tcp", ":"+Conf.Port) 35 | if err != nil { 36 | log.Panic(err) 37 | } 38 | 39 | for { 40 | // 接收TCP连接,返回一个net.Conn 41 | client, err := l.Accept() 42 | if err != nil { 43 | log.Panic("Panic", err) 44 | } 45 | // 收到请求后,调用handle进行处理 46 | go handle(client) 47 | } 48 | } 49 | 50 | func handle(client net.Conn) { 51 | defer func() { 52 | if err := recover(); err != nil { 53 | log.Panic(err) 54 | debug.PrintStack() 55 | } 56 | }() 57 | if client == nil { 58 | return 59 | } 60 | 61 | log.Println("JCTLog: client tcp tunnel connection: ", client.LocalAddr().String(), "->", client.RemoteAddr().String()) 62 | defer client.Close() 63 | // 随机取出一个代理 64 | paddr, ptype, _ := Proxy.GetAProxy() 65 | proxyAddr := ptype + "://" + paddr 66 | // 验证代理是否有效 67 | checkaddr := "http://myip.ipip.net" 68 | if Proxy.CheckProxy(proxyAddr, checkaddr) { 69 | log.Println(" 代理有效 ", proxyAddr) 70 | // 有效,使用端口转发 71 | PortForward(client, paddr) 72 | } else { 73 | log.Println(" 代理无效 ", proxyAddr) 74 | // 判断该代理是否在可用代理池,若在,则删除 75 | // 无效,使用自身代理 76 | lproxy(client) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /ProxyEntry/portforward.go: -------------------------------------------------------------------------------- 1 | package ProxyEntry 2 | 3 | import ( 4 | "log" 5 | "net" 6 | ) 7 | 8 | func PortForward(client net.Conn, targetaddr string) { 9 | // Read a header firstly in case you could have opportunity to check request 10 | // whether to decline or proceed the request 11 | buffer := make([]byte, 1024) 12 | n, err := client.Read(buffer) 13 | if err != nil { 14 | log.Printf("Unable to read from input, error: %s\n", err.Error()) 15 | return 16 | } 17 | // targetaddr = "223.82.106.253:3128" 18 | targetconn, err := net.Dial("tcp", targetaddr) 19 | if err != nil { 20 | log.Println("Unable to connect to: %s, error: %s\n", targetaddr, err.Error()) 21 | client.Close() 22 | return 23 | } 24 | n, err = targetconn.Write(buffer[:n]) 25 | if err != nil { 26 | log.Printf("Unable to write to output, error: %s\n", err.Error()) 27 | client.Close() 28 | targetconn.Close() 29 | return 30 | } 31 | go proxyRequest(client, targetconn) 32 | proxyRequest(targetconn, client) 33 | } 34 | -------------------------------------------------------------------------------- /ProxyEntry/proxyRequest.go: -------------------------------------------------------------------------------- 1 | package ProxyEntry 2 | 3 | import ( 4 | "net" 5 | // "fmt" 6 | ) 7 | 8 | // Forward all requests from r to w 9 | func proxyRequest(r net.Conn, w net.Conn) { 10 | defer r.Close() 11 | defer w.Close() 12 | 13 | var buffer = make([]byte, 4096000) 14 | for { 15 | n, err := r.Read(buffer) 16 | if err != nil { 17 | // fmt.Printf("Unable to read from input, error: %s\n", err.Error()) 18 | break 19 | } 20 | // fmt.Println(string(buffer[:n])) 21 | n, err = w.Write(buffer[:n]) 22 | if err != nil { 23 | // fmt.Printf("Unable to write to output, error: %s\n", err.Error()) 24 | break 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # (一)JCRandomProxy(随机代理)- 图形版 2 | 3 | JCRandomProxy【随机代理】Gui版 4 | ```shell 5 | Author: JC0o0l 6 | Wechat: JC_SecNotes 7 | ``` 8 | ## 功能 9 | - http代理 10 | - https代理 11 | - 定时代理校验 12 | - 随机代理 13 | 14 | ## 更新 15 | - GUI版发布 - 20200928 16 | 17 | ## 不足 18 | - 取决于所获取到的代理的质量 19 | - 日志模块不完善 20 | - 配置模块不完善 21 | 22 | ## 效果 23 | 24 | 开启后,在浏览器中配置http代理,之后查看IP,结果如下: 25 | ![1601306340500.png](https://github.com/chroblert/JCRandomProxy/blob/GUIVersion/img/1601306340500.png) 26 | ## 步骤 27 | 提前配置好[proxypool](https://github.com/jhao104/proxy_pool) 28 | 29 | 项目地址为: `https://github.com/jhao104/proxy_pool` 30 | 31 | 1\. 从GitHub上clone Gui版本的代码 32 | ```shell 33 | git clone -b GUIVersion https://github.com/chroblert/JCRandomProxy.git 34 | ``` 35 | 2\. 从release中下载最新版二进制程序 36 | ```shell 37 | https://github.com/chroblert/JCRandomProxy/releases 38 | ``` 39 | 3\. 执行后,界面如下 40 | 41 | ![1601305000116.png](https://github.com/chroblert/JCRandomProxy/blob/GUIVersion/img/1601305000116.png) 42 | 43 | > 执行后会发现出现一个cmd框,这个是故意这样的,方面出错时调试用的。若要不弹框,则需要使用如下命令重新进行编译 44 | > ```shell 45 | > go build -i -ldflags="-H windowsgui" 46 | > ``` 47 | 4\. 配置 48 | 图中有代理池、控制以及自定义三个面板是需要在启动前配置,说明如下: 49 | 50 | 代理池: 51 | - 代理池IP: 自己部署的proxypool所在的服务器IP 52 | - 代理池端口:自己部署的proxypool对外开放的端口 53 | 54 | 自定义: 55 | - 导入:打开对话框,从文件中导入代理到元代理池中 56 | - 保存:将自定义框中的代理保存到proxy.lst文件中去 57 | - 添加:手动输入代理 58 | - 删除:从元代理池中删去选定的代理 59 | > 元代理池是自定义模式下的概念:代表从文件中或手动添加的没有经过校验的代理存放的地方 60 | > 61 | > 要导入的文件中,每行一个代理,格式如下: 62 | > `protocol,ip:port` 63 | > 64 | > 例如:`http,127.0.0.1;8081` 65 | 66 | 控制: 67 | - 监听端口:JCRP监听在哪个端口 68 | - 代理模式: 69 | - 代理池:从proxypool中获取代理 70 | - 自定义:从文件中导入代理 71 | - 启动: 启动代理 72 | - 停止:停止代理 73 | - MIN:当可用代理池中的代理数量小于MIN时,则开始获取代理 74 | - MAX:当可用代理池中的代理数量等于MAX时,则停止获取代理 75 | - 超时:校验代理是否可用时的超时时间,以秒为单位 76 | 77 | 5\. 启动 78 | 79 | 点击启动后,JCRP会收集MAX数量的可用代理,从左下框中可以看到 80 | 81 | ![1601304925725.png](https://github.com/chroblert/JCRandomProxy/blob/GUIVersion/img/1601304925725.png) 82 | 83 | 6\. 可用代理操作说明 84 | 85 | - 追加: 将可用代理池中代理追加到proxy.lst文件中去 86 | - 覆盖: 将可用代理池中代理覆盖到proxy.lst文件 87 | - 删除: 删除可用代理池中选中的代理 88 | 89 | 90 | # (二)JCRandomProxy(随机代理)- 命令行版 91 | 92 | ## 功能: 93 | - http代理 94 | - 动态代理 95 | - 代理有效性校验 96 | 97 | ## 更新 98 | - https代理 - 20200831 99 | - 增加可用代理池 - 20200920 100 | - 增加输出日志到文件 - 20200921 101 | 102 | ## 安装: 103 | (一)源码安装 104 | ```shell 105 | git clone https://github.com/Chroblert/JCRandomProxy.git 106 | go run main.go 107 | ``` 108 | (二) 使用二进制文件 109 | ```shell 110 | git clone https://github.com/Chroblert/JCRandomProxy.git 111 | ``` 112 | 将适合自己系统的二进制文件拷贝到clone下来的目录下 113 | 114 | ## 使用说明: 115 | 该工具需与proxypool配合使用,或者将确定可以使用的代理IP写在proxy.lst文件中 116 | 117 | ## 配置说明: 118 | 119 | 参见config.ini 120 | 121 | ## 目录说明: 122 | ```shell 123 | Conf: 124 | - config.go # 配置相关 125 | - config.ini # 配置文件 126 | - proxy.lst # 确定可用的代理 127 | Proxy: 128 | - GetAProxy.go # 获取代理 129 | - GetAProxyA.go # 从proxypool中获取代理 130 | - GetAProxyB.go # 从proxy.lst中获取代理 131 | main.go 132 | ``` 133 | -------------------------------------------------------------------------------- /log.txt: -------------------------------------------------------------------------------- 1 | 2020/09/21 10:25:35 config.go:28: JCTest &{{false false false false false false false false false false false false [] =: = false 0 false} [{C:\Data\Go\src\JCRandomProxy\Conf\config.ini}] true {{0 0} 0 0 0 0} [DEFAULT main proxypool customproxy] [0 0 0 0] map[DEFAULT:[0xc00010c620] customproxy:[0xc00010ca80] main:[0xc00010c690] proxypool:[0xc00010c930]] } 2 | 2020/09/21 10:25:40 main.go:61: JCTLog: client tcp tunnel connection: [::1]:8081 -> [::1]:49487 3 | 2020/09/21 10:25:40 CheckProxy.go:42: JCTLog: 代理地址: 54.168.222.142:80 4 | 2020/09/21 10:25:40 CheckProxy.go:53: JCTLog: 目标URL: http://myip.ipip.net 5 | 2020/09/21 10:25:40 CheckProxy.go:71: JCTLog: http.ReadResponse: read tcp 192.168.14.109:49488->54.168.222.142:80: wsarecv: An existing connection was forcibly closed by the remote host. 6 | 2020/09/21 10:25:40 main.go:73: 代理无效 http://54.168.222.142:80 7 | 2020/09/21 10:25:40 localproxy.go:35: GET http://www.google.com/ 8 | 2020/09/21 10:25:45 main.go:61: JCTLog: client tcp tunnel connection: 127.0.0.1:8081 -> 127.0.0.1:49491 9 | 2020/09/21 10:25:45 CheckProxy.go:42: JCTLog: 代理地址: 38.77.36.35:8080 10 | 2020/09/21 10:25:45 main.go:61: JCTLog: client tcp tunnel connection: 127.0.0.1:8081 -> 127.0.0.1:49493 11 | 2020/09/21 10:25:45 CheckProxy.go:42: JCTLog: 代理地址: 211.137.52.159:8080 12 | 2020/09/21 10:25:45 CheckProxy.go:53: JCTLog: 目标URL: http://myip.ipip.net 13 | 2020/09/21 10:25:45 CheckProxy.go:53: JCTLog: 目标URL: http://myip.ipip.net 14 | 2020/09/21 10:25:45 CheckProxy.go:93: 包含 211.137.52.159:8080 15 | 2020/09/21 10:25:45 CheckProxy.go:28: 当前可用代理池: map[f303fa798d2b086c9fcf88614b542947:{http 211.137.52.159 8080}] 16 | 2020/09/21 10:25:45 main.go:69: 代理有效 http://211.137.52.159:8080 17 | 2020/09/21 10:25:45 main.go:61: JCTLog: client tcp tunnel connection: 127.0.0.1:8081 -> 127.0.0.1:49496 18 | 2020/09/21 10:25:45 CheckProxy.go:42: JCTLog: 代理地址: 103.141.182.100:80 19 | 2020/09/21 10:25:45 CheckProxy.go:53: JCTLog: 目标URL: http://myip.ipip.net 20 | 2020/09/21 10:25:46 main.go:61: JCTLog: client tcp tunnel connection: 127.0.0.1:8081 -> 127.0.0.1:49498 21 | 2020/09/21 10:25:46 CheckProxy.go:42: JCTLog: 代理地址: 223.82.106.253:3128 22 | 2020/09/21 10:25:46 CheckProxy.go:53: JCTLog: 目标URL: http://myip.ipip.net 23 | 2020/09/21 10:25:46 CheckProxy.go:93: 包含 38.77.36.35:8080 24 | 2020/09/21 10:25:46 CheckProxy.go:28: 当前可用代理池: map[27ffd890d2a9d2fc13ad7e853d62c6ff:{http 38.77.36.35 8080} f303fa798d2b086c9fcf88614b542947:{http 211.137.52.159 8080}] 25 | 2020/09/21 10:25:46 main.go:69: 代理有效 http://38.77.36.35:8080 26 | 2020/09/21 10:25:46 CheckProxy.go:93: 包含 223.82.106.253:3128 27 | 2020/09/21 10:25:46 CheckProxy.go:28: 当前可用代理池: map[27ffd890d2a9d2fc13ad7e853d62c6ff:{http 38.77.36.35 8080} 5470c9ad2cb8a0086d3c4ca65794e96a:{http 223.82.106.253 3128} f303fa798d2b086c9fcf88614b542947:{http 211.137.52.159 8080}] 28 | 2020/09/21 10:25:46 main.go:69: 代理有效 http://223.82.106.253:3128 29 | 2020/09/21 10:25:46 CheckProxy.go:93: 包含 103.141.182.100:80 30 | 2020/09/21 10:25:46 CheckProxy.go:28: 当前可用代理池: map[2738a436b86458c3c5e74eab47d8f889:{http 103.141.182.100 80} 27ffd890d2a9d2fc13ad7e853d62c6ff:{http 38.77.36.35 8080} 5470c9ad2cb8a0086d3c4ca65794e96a:{http 223.82.106.253 3128} f303fa798d2b086c9fcf88614b542947:{http 211.137.52.159 8080}] 31 | 2020/09/21 10:25:46 main.go:69: 代理有效 http://103.141.182.100:80 32 | 2020/09/21 10:26:01 localproxy.go:56: JCTLog: Dial: dial tcp 172.217.27.132:80: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 33 | 2020/09/21 10:26:07 portforward.go:20: Unable to connect to: %s, error: %s 34 | 223.82.106.253:3128 dial tcp 223.82.106.253:3128: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 35 | 2020/09/21 10:26:07 main.go:61: JCTLog: client tcp tunnel connection: 127.0.0.1:8081 -> 127.0.0.1:49504 36 | 2020/09/21 10:26:07 CheckProxy.go:42: JCTLog: 代理地址: 54.168.222.142:80 37 | 2020/09/21 10:26:07 CheckProxy.go:53: JCTLog: 目标URL: http://myip.ipip.net 38 | 2020/09/21 10:26:08 CheckProxy.go:93: 包含 54.168.222.142:80 39 | 2020/09/21 10:26:08 CheckProxy.go:28: 当前可用代理池: map[2738a436b86458c3c5e74eab47d8f889:{http 103.141.182.100 80} 27ffd890d2a9d2fc13ad7e853d62c6ff:{http 38.77.36.35 8080} 5470c9ad2cb8a0086d3c4ca65794e96a:{http 223.82.106.253 3128} 6b4cd7718601e8002daa2a32a78bc8fa:{http 54.168.222.142 80} f303fa798d2b086c9fcf88614b542947:{http 211.137.52.159 8080}] 40 | 2020/09/21 10:26:08 main.go:69: 代理有效 http://54.168.222.142:80 41 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "JCRandomProxy/ProxyEntry" 3 | func main() { 4 | ProxyEntry.Proxymain() 5 | } 6 | --------------------------------------------------------------------------------