Skip to content

Commit 18aca2a

Browse files
author
taro
committed
add debug
1 parent 774e754 commit 18aca2a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

check.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ func CheckProxyAlive(proxyURL string) (respBody string, timeout int64, avail boo
4141

4242
// http://cip.cc isn't stable enough for proxies alive test.
4343
resp, err := httpclient.Get("https://www.baidu.com/robots.txt")
44-
44+
4545
if err != nil {
46+
DebugLog(Warn("[!] %v: %v", proxyURL, err))
4647
return "", 0, false
4748
}
4849
defer resp.Body.Close()
@@ -52,7 +53,8 @@ func CheckProxyAlive(proxyURL string) (respBody string, timeout int64, avail boo
5253
return "", 0, false
5354
}
5455
if !strings.Contains(string(body), "Baiduspider-image") {
55-
return "", 0, false
56+
DebugLog(Warn("[!] err live %s resp: %v", proxyURL, err))
57+
return "", 0, false
5658
}
5759
return string(body), timeout, true
5860
}
@@ -71,13 +73,15 @@ func CheckProxyWithCheckURL(proxyURL string, checkURL string, checkURLwords stri
7173
startTime := time.Now()
7274
resp, err := httpclient.Get(checkURL)
7375
if err != nil {
76+
DebugLog(Warn("[!] httpclient.Get: %v", err))
7477
return 0, false
7578
}
7679
defer resp.Body.Close()
7780
timeout = int64(time.Since(startTime))
7881
body, err := io.ReadAll(resp.Body)
7982

8083
if err != nil {
84+
DebugLog(Warn("[!] io.ReadAll: %v", err))
8185
return 0, false
8286
}
8387

cmd/rotateproxy/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func init() {
4141
flag.IntVar(&baseCfg.IPRegionFlag, "region", 0, "0: all 1: cannot bypass gfw 2: bypass gfw")
4242
flag.IntVar(&baseCfg.SelectStrategy, "strategy", 3, "0: random, 1: Select the one with the shortest timeout, 2: Select the two with the shortest timeout, ...")
4343
flag.IntVar(&pageCount, "page", 5, "the page count you want to crawl")
44+
flag.BoolVar(&rotateproxy.IsDebug, "debug", false, "debug mode to see log")
4445
flag.Parse()
4546

4647
if checkURL != "https://www.google.com" && checkURLwords == "Copyright The Closure Library Authors" {

util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rotateproxy
22

33
import (
44
"errors"
5+
"fmt"
56
"io"
67
"log"
78
"math/rand"
@@ -102,9 +103,16 @@ var (
102103
Noticeln = color.New(color.FgBlue).SprintFunc()
103104
Info = color.New(color.FgGreen).SprintfFunc()
104105
Warn = color.New(color.FgRed).SprintfFunc()
106+
IsDebug = false
105107
)
106108

107109
var (
108110
InfoLog = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile).Println
109111
ErrorLog = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile).Println
110112
)
113+
114+
func DebugLog(content string) {
115+
if IsDebug {
116+
fmt.Print(content)
117+
}
118+
}

0 commit comments

Comments
 (0)