代码拉取完成,页面将自动刷新
package main
import (
"net/http"
"net/url"
"net/http/httputil"
"log"
"net"
"time"
"context"
"github.com/bogdanovich/dns_resolver"
"strings"
)
type handle struct {
reverseProxy string
}
func (this *handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println(r.RemoteAddr + " " + r.Method + " " + r.URL.String() + " " + r.Proto + " " + r.UserAgent())
remote, err := url.Parse(this.reverseProxy)
if err != nil {
log.Fatalln(err)
}
dialer := &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}
http.DefaultTransport.(*http.Transport).DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
remote := strings.Split(addr, ":")
if cmd.ip == "" {
resolver := dns_resolver.New([]string{"114.114.114.114", "114.114.115.115", "119.29.29.29", "223.5.5.5", "8.8.8.8", "208.67.222.222", "208.67.220.220"})
resolver.RetryTimes = 5
ip, err := resolver.LookupHost(remote[0])
if err != nil {
log.Println(err)
}
cmd.ip = ip[0].String()
}
addr = cmd.ip + ":" + remote[1]
return dialer.DialContext(ctx, network, addr)
}
proxy := httputil.NewSingleHostReverseProxy(remote)
r.Host = remote.Host
proxy.ServeHTTP(w, r)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。