-
-
Save dimm999/12e9f519a8fcaf5061a7 to your computer and use it in GitHub Desktop.
proxy check by golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129.24.51.99 21320 | |
24.158.231.6 80 | |
54.161.139.184 5555 | |
46.38.166.124 80 | |
192.121.107.107 80 | |
177.91.192.116 8080 | |
1.0.138.14 8080 | |
107.150.29.157 3128 | |
98.145.71.245 21320 | |
68.195.17.204 21320 | |
74.208.7.207 80 | |
50.112.105.221 3128 | |
186.46.115.22 3128 | |
104.237.151.99 3128 | |
23.25.40.65 80 | |
64.186.47.179 3128 | |
186.89.114.173 8080 | |
137.135.166.225 8121 | |
190.205.28.214 8080 | |
190.207.227.186 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"net/url" | |
"runtime" | |
"strings" | |
"time" | |
) | |
type QueryResp struct { | |
Addr string | |
Time float64 | |
} | |
func query(ip string, port string, c chan QueryResp) { | |
start_ts := time.Now() | |
var timeout = time.Duration(15 * time.Second) | |
host := fmt.Sprintf("%s:%s", ip, port) | |
url_proxy := &url.URL{Host: host} | |
client := &http.Client{ | |
Transport: &http.Transport{Proxy: http.ProxyURL(url_proxy)}, | |
Timeout: timeout} | |
resp, err := client.Get("http://err.taobao.com/error1.html") | |
if err != nil { | |
c <- QueryResp{Addr: host, Time: float64(-1)} | |
return | |
} | |
defer resp.Body.Close() | |
body, _ := ioutil.ReadAll(resp.Body) | |
time_diff := time.Now().UnixNano() - start_ts.UnixNano() | |
if strings.Contains(string(body), "alibaba.com") { | |
c <- QueryResp{Addr: host, Time: float64(time_diff) / 1e9} | |
} else { | |
c <- QueryResp{Addr: host, Time: float64(-1)} | |
} | |
} | |
func main() { | |
dat, _ := ioutil.ReadFile("ip.txt") | |
dats := strings.Split(strings.TrimSuffix(string(dat), "\n"), "\n") | |
runtime.GOMAXPROCS(4) | |
resp_chan := make(chan QueryResp, 10) | |
for _, addr := range dats { | |
addrs := strings.SplitN(addr, string(' '), 2) | |
ip, port := addrs[0], addrs[1] | |
go query(ip, port, resp_chan) | |
} | |
for _, _ = range dats { | |
//fmt.Println(i, j) | |
r := <-resp_chan | |
if r.Time > 1e-9 { | |
fmt.Printf("%s %v\n", r.Addr, r.Time) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment