Skip to content

Commit 5cd4234

Browse files
committed
Merge branch 'master' of github.com:akkuman/rotateproxy
2 parents a82e359 + 743f91d commit 5cd4234

File tree

13 files changed

+303
-241
lines changed

13 files changed

+303
-241
lines changed

.github/workflows/release.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ on:
77

88
jobs:
99
build-rotateproxy:
10-
runs-on: ubuntu-18.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v4
1414

15-
- name: Setup Golang
16-
uses: actions/setup-go@v2
15+
- name: Set up Go
16+
uses: actions/setup-go@v4
1717
with:
18-
go-version: 1.17
18+
go-version: 1.21
19+
cache: true
1920

2021
- name: Run GoReleaser
21-
uses: goreleaser/goreleaser-action@v4
22+
uses: goreleaser/goreleaser-action@v5
2223
with:
24+
distribution: goreleaser
2325
version: latest
2426
args: release --clean
25-
workdir: cmd/rotateproxy
2627
env:
2728
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
*.exe
2+
*.exe~
23
.history
34
.vscode
45
*.zip
5-
cmd/rotateproxy/db.db
6-
build
6+
build
7+
*.ps1
8+
*.db
9+
cmd/rotateproxy/db.db*

.goreleaser.yml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1+
before:
2+
hooks:
3+
- go mod tidy
14
builds:
2-
- skip: true
5+
- env: [CGO_ENABLED=0]
6+
goos:
7+
- linux
8+
- windows
9+
- darwin
10+
- freebsd
11+
goarch:
12+
- amd64
13+
- arm64
14+
dir: .
15+
main: ./cmd/rotateproxy
16+
flags:
17+
# trims path
18+
- -trimpath
19+
ldflags:
20+
# use commit date instead of current date as main.date
21+
# only needed if you actually use those things in your main package, otherwise can be ignored.
22+
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }}
323
checksum:
424
name_template: 'checksums.txt'
25+
changelog:
26+
sort: asc
27+
filters:
28+
exclude:
29+
- '^docs:'
30+
- '^test:'
531
release:
6-
# Same as for github
7-
# Note: it can only be one: either github, gitlab or gitea
8-
github:
9-
owner: akkuman
10-
name: rotateproxy
11-
12-
draft: false
13-
14-
# You can add extra pre-existing files to the release.
15-
# The filename on the release will be the last part of the path (base). If
16-
# another file with the same name exists, the latest one found will be used.
17-
# Defaults to empty.
18-
extra_files:
19-
- glob: ./build/*
32+
name_template: 'v{{ .Version }}'
33+
archives:
34+
- format: zip

README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# rotateproxy
22

3-
利用fofa搜索socks5开放代理进行代理池轮切的工具
3+
利用 fofa 搜索 socks5 开放代理进行代理池轮切的工具
44

55
## 特性
66

@@ -10,8 +10,12 @@
1010
## 帮助
1111

1212
```shell
13-
> .\rotateproxy.exe -h
13+
.\rotateproxy.exe -h
1414
Usage of rotateproxy.exe:
15+
-check string
16+
check url (default "https://www.google.com")
17+
-checkWords string
18+
words in check url (default "Copyright The Closure Library Authors")
1519
-email string
1620
email address
1721
-l string
@@ -20,16 +24,30 @@ Usage of rotateproxy.exe:
2024
the page count you want to crawl (default 5)
2125
-pass string
2226
authentication password
27+
-proxy string
28+
proxy
2329
-region int
2430
0: all 1: cannot bypass gfw 2: bypass gfw
2531
-rule string
2632
search rule (default "protocol==\"socks5\" && \"Version:5 Method:No Authentication(0x00)\" && after=\"2025-03-01\" && country=\"CN\"")
33+
-strategy int
34+
0: random, 1: Select the one with the shortest timeout (default 1)
2735
-token string
2836
token
2937
-user string
3038
authentication username
3139
```
3240

41+
### 参数说明
42+
43+
- `-check``-checkWords`: 如果你希望你找出来的代理能够访问某个特定网站,可以使用 `-check``-checkWords`,checkWords 为一串字符,用来保证确定是访问的该网站,比如 `-check "https://www.google.com" -checkWords "Copyright The Closure Library Authors"`,目的就是找出来的代理能够访问 [https://www.google.com](https://www.google.com),并且返回内容中含有 `Copyright The Closure Library Authors`
44+
- `-email``-token`: fofa 的邮箱和 token
45+
- `-l`: 本服务的 socks5 监听地址
46+
- `-page`: fofa 结果默认爬取多少页(每页固定爬取 100 条)
47+
- `-user``-pass`: 本服务的 socks5 用户名密码认证
48+
- `-proxy`: 如果提供,将使用该 proxy 来访问 fofa 获取代理地址
49+
- `-region`: 用来筛选是否能访问谷歌
50+
3351
## 安装
3452

3553
```shell
@@ -43,7 +61,7 @@ curl -L -o rotateproxy 'https://github.com/akkuman/rotateproxy/releases/latest/d
4361
chmod +x ./rotateproxy
4462
```
4563

46-
### 安装为linux服务(感谢 [@Rvn0xsy](https://github.com/Rvn0xsy) 提供 [PR](https://github.com/akkuman/rotateproxy/pull/4)
64+
### 安装为 linux 服务(感谢 [@Rvn0xsy](https://github.com/Rvn0xsy) 提供 [PR](https://github.com/akkuman/rotateproxy/pull/4)
4765

4866
1. 下载相关文件
4967

@@ -54,6 +72,7 @@ curl -L -o /usr/lib/systemd/system/rotateproxy.service 'https://raw.githubuserco
5472
```
5573

5674
2. 查看 [rotateproxy.service.example](./rotateproxy.service.example) 文件示例,将 `/usr/lib/systemd/system/rotateproxy.service` 文件中的 `ExecStart` 的命令替换为你自己的命令
75+
5776
3. 启动服务
5877

5978
```shell
@@ -70,17 +89,15 @@ systemctl enable rotateproxy.service
7089
4. 使用
7190

7291
```bash
73-
https_proxy=socks5://{ip}:{port} curl https://example.com
92+
curl --proxy "socks5://127.0.0.1:8899" https://example.com
7493
```
7594

7695
## 效果展示
7796

7897
![](./pics/curl-run.jpg)
7998

80-
## mac 交叉编译
99+
## 开发
81100

82-
```bash
83-
brew install FiloSottile/musl-cross/musl-cross
84-
cd cmd/rotateproxy
85-
CC=x86_64-linux-musl-gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-linkmode external -extldflags -static"
86-
```
101+
### 注意
102+
103+
1. 该项目为了交叉编译方便,采用的 cgo-free 的 sqlite3 库,该库默认可能开启了 `SQLITE_FCNTL_PERSIST_WAL`,导致就算 Close 了数据库连接依旧不会删除 wal 文件,所以可能你会在 .db 旁边看到 -shm 和 -wal 文件,如果需要共享该数据库,请将这三个文件一并打包发送

check.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package rotateproxy
22

33
import (
4+
"context"
45
"crypto/tls"
5-
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/url"
9+
"strings"
910
"time"
1011

1112
"github.com/tidwall/gjson"
@@ -36,7 +37,8 @@ func CheckProxyAlive(proxyURL string) (respBody string, timeout int64, avail boo
3637
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
3738
DisableKeepAlives: true,
3839
},
39-
Timeout: 20 * time.Second,
40+
// shorter timeout for better proxies
41+
Timeout: 5 * time.Second,
4042
}
4143
startTime := time.Now()
4244
resp, err := httpclient.Get("https://whois.pconline.com.cn/ipJson.jsp?json=true&ip=")
@@ -45,7 +47,7 @@ func CheckProxyAlive(proxyURL string) (respBody string, timeout int64, avail boo
4547
}
4648
defer resp.Body.Close()
4749
timeout = int64(time.Since(startTime))
48-
body, err := ioutil.ReadAll(resp.Body)
50+
body, err := io.ReadAll(resp.Body)
4951
if err != nil {
5052
return "", 0, false
5153
}
@@ -55,8 +57,8 @@ func CheckProxyAlive(proxyURL string) (respBody string, timeout int64, avail boo
5557
return string(body), timeout, true
5658
}
5759

58-
func CheckProxyWithCheckURL(proxyURL string, checkURL string) (timeout int64, avail bool) {
59-
fmt.Printf("check %s: %s\n", proxyURL, checkURL)
60+
func CheckProxyWithCheckURL(proxyURL string, checkURL string, checkURLwords string) (timeout int64, avail bool) {
61+
// InfoLog(Notice("check %s: %s", proxyURL, checkURL))
6062
proxy, _ := url.Parse(proxyURL)
6163
httpclient := &http.Client{
6264
Transport: &http.Transport{
@@ -73,46 +75,58 @@ func CheckProxyWithCheckURL(proxyURL string, checkURL string) (timeout int64, av
7375
}
7476
defer resp.Body.Close()
7577
timeout = int64(time.Since(startTime))
78+
body, err := io.ReadAll(resp.Body)
79+
80+
if err != nil {
81+
return 0, false
82+
}
7683

7784
// TODO: support regex
7885
if resp.StatusCode != 200 {
7986
return 0, false
8087
}
8188

89+
if !strings.Contains(string(body), checkURLwords) {
90+
return 0, false
91+
}
92+
8293
return timeout, true
8394
}
8495

85-
func StartCheckProxyAlive(checkURL string) {
96+
func StartCheckProxyAlive(ctx context.Context, checkURL string, checkURLwords string) {
8697
go func() {
8798
ticker := time.NewTicker(120 * time.Second)
99+
defer ticker.Stop()
88100
for {
89101
select {
90102
case <-crawlDone:
91-
fmt.Println("Checking")
92-
checkAlive(checkURL)
93-
fmt.Println("Check done")
103+
InfoLog(Noticeln("Checkings"))
104+
checkAlive(checkURL, checkURLwords)
105+
InfoLog(Noticeln("Check done"))
94106
case <-ticker.C:
95-
checkAlive(checkURL)
107+
checkAlive(checkURL, checkURLwords)
108+
case <- ctx.Done():
109+
return
96110
}
97111
}
98112
}()
99113
}
100114

101-
func checkAlive(checkURL string) {
115+
func checkAlive(checkURL string, checkURLwords string) {
102116
proxies, err := QueryProxyURL()
103117
if err != nil {
104-
fmt.Printf("[!] query db error: %v\n", err)
118+
ErrorLog(Warn("[!] query db error: %v", err))
105119
}
106120
for i := range proxies {
107121
proxy := proxies[i]
108122
go func() {
109123
respBody, timeout, avail := CheckProxyAlive(proxy.URL)
110124
if avail {
111125
if checkURL != "" {
112-
timeout, avail = CheckProxyWithCheckURL(proxy.URL, checkURL)
126+
timeout, avail = CheckProxyWithCheckURL(proxy.URL, checkURL, checkURLwords)
113127
}
114128
if avail {
115-
fmt.Printf("%v 可用\n", proxy.URL)
129+
InfoLog(Notice("%v 可用", proxy.URL))
116130
SetProxyURLAvail(proxy.URL, timeout, CanBypassGFW(respBody))
117131
return
118132
}

cmd/rotateproxy/.goreleaser.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)