Skip to content

Commit

Permalink
优化了代理判断的条件,从httpcode改为了从返回的页面中匹配关键字
Browse files Browse the repository at this point in the history
  • Loading branch information
netxfly committed Dec 6, 2017
1 parent 3521e09 commit f68ecb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import (

"net/http"
"net/url"
"io/ioutil"
"strings"
)

var (
HttpProxyProtocol = []string{"http", "https"}
WebUrl = "http://www.163.com"
WebUrl = "http://email.163.com/"
)

func CheckHttpProxy(ip string, port int, protocol string) (err error, isProxy bool, proxyInfo models.ProxyInfo) {
Expand All @@ -53,8 +55,12 @@ func CheckHttpProxy(ip string, port int, protocol string) (err error, isProxy bo
util.Log.Debugf("Checking proxy: %v", rawProxyUrl)
resp, err := client.Get(WebUrl)
if err == nil {
if resp.StatusCode >= http.StatusOK {
isProxy = true
if resp.StatusCode == http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err == nil && strings.Contains(string(body), "网易免费邮箱") {
isProxy = true
}

}
}
}
Expand Down
12 changes: 9 additions & 3 deletions proxy/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ THE SOFTWARE.
package proxy

import (
"net/http"
"h12.me/socks"

"proxy_scanner/models"
"proxy_scanner/util"

"fmt"
"time"
"net/http"
"io/ioutil"
"strings"
)

var (
Expand All @@ -53,8 +56,11 @@ func CheckSockProxy(ip string, port, protocol int) (err error, isProxy bool, pro
util.Log.Debugf("Checking proxy: %v", fmt.Sprintf("%v://%v:%v", SockProxyProtocol[protocol], ip, port))
resp, err := httpClient.Get(WebUrl)
if err == nil {
if resp.StatusCode >= http.StatusOK {
isProxy = true
if resp.StatusCode == http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err == nil && strings.Contains(string(body), "网易免费邮箱") {
isProxy = true
}
}
}
return err, isProxy, proxyInfo
Expand Down

0 comments on commit f68ecb0

Please sign in to comment.