mirror of
https://github.com/byReqz/probehost2.git
synced 2024-11-14 19:23:14 +00:00
adapt to possible reverse proxy
This commit is contained in:
parent
ba622db043
commit
ccb2a41305
10
main.go
10
main.go
@ -15,11 +15,13 @@ var logstdout = log.New()
|
|||||||
var logfile = log.New()
|
var logfile = log.New()
|
||||||
|
|
||||||
var listenport int
|
var listenport int
|
||||||
|
var usexforwardedfor bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var logfilepath string
|
var logfilepath string
|
||||||
flag.StringVar(&logfilepath, "logfilepath", "probehost2.log", "sets the output file for the log")
|
flag.StringVar(&logfilepath, "logfilepath", "probehost2.log", "sets the output file for the log")
|
||||||
flag.IntVar(&listenport, "port", 8000, "sets the port to listen on")
|
flag.IntVar(&listenport, "port", 8000, "sets the port to listen on")
|
||||||
|
flag.BoolVar(&usexforwardedfor, "use-x-forwarded-for", true, "specifies whether to show x-forwarded-for or the requesting IP")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logstdout.SetFormatter(&log.TextFormatter{
|
logstdout.SetFormatter(&log.TextFormatter{
|
||||||
@ -94,10 +96,16 @@ func prerunner(req *http.Request, cmd string, cmdopts map[string]string, default
|
|||||||
}
|
}
|
||||||
var res string
|
var res string
|
||||||
var args []string
|
var args []string
|
||||||
|
var remoteaddr string
|
||||||
|
if req.Header.Get("X-Forwarded-For") != "" && usexforwardedfor != false {
|
||||||
|
remoteaddr = req.Header.Get("X-Forwarded-For")
|
||||||
|
} else {
|
||||||
|
remoteaddr = req.RemoteAddr
|
||||||
|
}
|
||||||
for _, host := range hosts {
|
for _, host := range hosts {
|
||||||
args = append(args, opts...)
|
args = append(args, opts...)
|
||||||
args = append(args, host)
|
args = append(args, host)
|
||||||
res = fmt.Sprint(res, runner(req.RemoteAddr, cmd, args...), "\n")
|
res = fmt.Sprint(res, runner(remoteaddr, cmd, args...), "\n")
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user