You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
wormhole-client/test_proxy_force.go

78 lines
1.6 KiB

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("=== 测试完成 ===")
}