修复HTTP代理处理和IP地址路由匹配问题 - 修复HTTP代理请求URL格式转换问题 - 修复ReadResponse调用参数错误 - 修复IP地址无法匹配强制代理规则的问题 - 添加101.34.16.52到强制代理列表 - 添加调试日志以便问题排查
parent
e34d8c600c
commit
3c1896a946
@ -0,0 +1,78 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"io" |
||||||
|
"net/http" |
||||||
|
"net/url" |
||||||
|
"time" |
||||||
|
) |
||||||
|
|
||||||
|
func testProxyAccess(targetURL, proxyURL string) { |
||||||
|
fmt.Printf("Testing %s via proxy %s...\n", targetURL, proxyURL) |
||||||
|
|
||||||
|
// 创建代理
|
||||||
|
proxy, err := url.Parse(proxyURL) |
||||||
|
if err != nil { |
||||||
|
fmt.Printf("❌ Invalid proxy URL: %v\n", err) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// 创建带代理的HTTP客户端
|
||||||
|
client := &http.Client{ |
||||||
|
Transport: &http.Transport{ |
||||||
|
Proxy: http.ProxyURL(proxy), |
||||||
|
}, |
||||||
|
Timeout: 20 * time.Second, |
||||||
|
} |
||||||
|
|
||||||
|
resp, err := client.Get(targetURL) |
||||||
|
if err != nil { |
||||||
|
fmt.Printf("❌ Failed: %v\n", err) |
||||||
|
return |
||||||
|
} |
||||||
|
defer resp.Body.Close() |
||||||
|
|
||||||
|
// 读取响应
|
||||||
|
body, err := io.ReadAll(resp.Body) |
||||||
|
if err != nil { |
||||||
|
fmt.Printf("❌ Failed to read response: %v\n", err) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Printf("✅ Success: %s (Status: %d, Size: %d bytes)\n", targetURL, resp.StatusCode, len(body)) |
||||||
|
|
||||||
|
// 如果是IP查询,显示结果
|
||||||
|
if targetURL == "https://httpbin.org/ip" || targetURL == "http://httpbin.org/ip" { |
||||||
|
fmt.Printf(" IP Response: %s\n", string(body)) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println("=== 强制代理测试 ===") |
||||||
|
|
||||||
|
proxyURL := "http://127.0.0.1:9090" |
||||||
|
|
||||||
|
// 测试目标 - 科学上网常用网站
|
||||||
|
targets := []string{ |
||||||
|
"https://httpbin.org/ip", |
||||||
|
"https://www.google.com", |
||||||
|
"https://github.com", |
||||||
|
"https://www.youtube.com", |
||||||
|
"https://twitter.com", |
||||||
|
"https://facebook.com", |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Printf("通过代理 %s 强制访问以下网站:\n\n", proxyURL) |
||||||
|
|
||||||
|
for i, target := range targets { |
||||||
|
fmt.Printf("%d. ", i+1) |
||||||
|
testProxyAccess(target, proxyURL) |
||||||
|
fmt.Println() |
||||||
|
|
||||||
|
// 避免请求过快
|
||||||
|
time.Sleep(2 * time.Second) |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Println("=== 测试完成 ===") |
||||||
|
} |
Loading…
Reference in new issue