summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsjlleo <[email protected]>2022-05-21 17:17:33 +0800
committersjlleo <[email protected]>2022-05-21 17:17:33 +0800
commited8f48835c9edc17a417abb8f6d472b20e5cff6d (patch)
tree4951e89e18ae7f552230460e89e22b900ee5ae0b
parentcd8251b93bd992824665a0b6111cee889189c1d4 (diff)
Add: proxy modulev3.1.0
-rw-r--r--main.go2
-rw-r--r--util/request.go13
-rw-r--r--verify/ipv4.go2
-rw-r--r--verify/ipv6.go2
-rw-r--r--verify/verify.go1
5 files changed, 15 insertions, 5 deletions
diff --git a/main.go b/main.go
index dc2c726..76c1447 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,7 @@ import (
var custom = flag.String("custom", "", "自定义测试NF影片ID\n绝命毒师的ID是70143836")
var address = flag.String("address", "", "本机网卡的IP")
+var proxy = flag.String("proxy", "", "代理地址")
func main() {
@@ -17,6 +18,7 @@ func main() {
r := verify.NewVerify(verify.Config{
LocalAddr: *address,
Custom: *custom,
+ Proxy: *proxy,
})
printer.Print(*r)
diff --git a/util/request.go b/util/request.go
index c3227b7..12d2acb 100644
--- a/util/request.go
+++ b/util/request.go
@@ -10,7 +10,9 @@ import (
"time"
)
-func RequestIP(requrl string, ip string, localAddr string) (string, error) {
+func RequestIP(requrl string, ip string, localAddr string, proxyUrl string) (string, error) {
+ var proxy *url.URL
+ var err error
if ip == "" {
return "", errors.New("IP is empty")
}
@@ -23,11 +25,16 @@ func RequestIP(requrl string, ip string, localAddr string) (string, error) {
ip = host
}
newrequrl := strings.Replace(requrl, host, ip, 1)
+ if proxyUrl != "" {
+ if proxy, err = url.Parse(proxyUrl); err != nil {
+ return "", errors.New("proxy parse error")
+ }
+ }
+
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{ServerName: host},
- // goodryb pull
- Proxy: http.ProxyFromEnvironment,
+ Proxy: http.ProxyURL(proxy),
DialContext: (&net.Dialer{
LocalAddr: &net.TCPAddr{
IP: net.ParseIP(localAddr),
diff --git a/verify/ipv4.go b/verify/ipv4.go
index 89a0763..b7275b3 100644
--- a/verify/ipv4.go
+++ b/verify/ipv4.go
@@ -78,7 +78,7 @@ func (v *IPv4Verifier) upgradeStatus(status int) {
func (v *IPv4Verifier) UnblockTest(MoiveID int) {
testURL := NetflixURL_PREFIX + strconv.Itoa(MoiveID)
- if reCode, err := util.RequestIP(testURL, v.IP, v.LocalAddr); err != nil {
+ if reCode, err := util.RequestIP(testURL, v.IP, v.LocalAddr, v.Proxy); err != nil {
if err.Error() == "Banned" {
v.unblockTestChan <- UnblockTestResult{MoiveID, "", nil}
} else {
diff --git a/verify/ipv6.go b/verify/ipv6.go
index 2da879d..e39455b 100644
--- a/verify/ipv6.go
+++ b/verify/ipv6.go
@@ -78,7 +78,7 @@ func (v *IPv6Verifier) upgradeStatus(status int) {
func (v *IPv6Verifier) UnblockTest(MoiveID int) {
testURL := NetflixURL_PREFIX + strconv.Itoa(MoiveID)
- if reCode, err := util.RequestIP(testURL, v.IP, v.LocalAddr); err != nil {
+ if reCode, err := util.RequestIP(testURL, v.IP, v.LocalAddr, v.Proxy); err != nil {
if err.Error() == "Banned" {
v.unblockTestChan <- UnblockTestResult{MoiveID, "", nil}
} else {
diff --git a/verify/verify.go b/verify/verify.go
index 38e2f60..ddf7db7 100644
--- a/verify/verify.go
+++ b/verify/verify.go
@@ -32,6 +32,7 @@ type VerifyResult struct {
type Config struct {
LocalAddr string
Custom string
+ Proxy string
}
type VerifyResponse struct {