mirror of
https://github.com/ehang-io/nps.git
synced 2025-07-04 22:00:43 +00:00
adjust external ip
This commit is contained in:
parent
927038fd4c
commit
91c1ffc6ce
@ -109,8 +109,8 @@ func ChangeHostAndHeader(r *http.Request, host string, header string, addr strin
|
|||||||
}
|
}
|
||||||
addr = strings.Split(addr, ":")[0]
|
addr = strings.Split(addr, ":")[0]
|
||||||
if prior, ok := r.Header["X-Forwarded-For"]; ok {
|
if prior, ok := r.Header["X-Forwarded-For"]; ok {
|
||||||
addr = strings.Join(prior, ", ") + ", " + addr
|
addr = strings.Join(prior, ", ") + ", " + addr
|
||||||
}
|
}
|
||||||
r.Header.Set("X-Forwarded-For", addr)
|
r.Header.Set("X-Forwarded-For", addr)
|
||||||
r.Header.Set("X-Real-IP", addr)
|
r.Header.Set("X-Real-IP", addr)
|
||||||
}
|
}
|
||||||
@ -396,3 +396,14 @@ func GetExtFromPath(path string) string {
|
|||||||
}
|
}
|
||||||
return string(re.Find([]byte(s[0])))
|
return string(re.Find([]byte(s[0])))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func GetExternalIp() string {
|
||||||
|
resp, err := http.Get("http://myexternalip.com/raw")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
content, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
return string(content)
|
||||||
|
}
|
||||||
|
@ -174,7 +174,12 @@ func (s *Sock5ModeServer) sendUdpReply(writeConn net.Conn, c net.Conn, rep uint8
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var serveExternalIp string
|
||||||
|
|
||||||
func (s *Sock5ModeServer) handleUDP(c net.Conn) {
|
func (s *Sock5ModeServer) handleUDP(c net.Conn) {
|
||||||
|
if serveExternalIp == "" {
|
||||||
|
serveExternalIp = common.GetExternalIp()
|
||||||
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
addrType := make([]byte, 1)
|
addrType := make([]byte, 1)
|
||||||
c.Read(addrType)
|
c.Read(addrType)
|
||||||
@ -213,9 +218,8 @@ func (s *Sock5ModeServer) handleUDP(c net.Conn) {
|
|||||||
logs.Error("listen local reply udp port error")
|
logs.Error("listen local reply udp port error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// reply the local addr
|
// reply the local addr
|
||||||
s.sendUdpReply(c, reply, succeeded, "106.12.146.199")
|
s.sendUdpReply(c, reply, succeeded, serveExternalIp)
|
||||||
defer reply.Close()
|
defer reply.Close()
|
||||||
|
|
||||||
// new a tunnel to client
|
// new a tunnel to client
|
||||||
|
Loading…
x
Reference in New Issue
Block a user