mirror of
https://github.com/byReqz/probehost2.git
synced 2025-07-01 10:30:48 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
2427e58cf6
|
|||
7b47ca1c58
|
|||
e4d0d9bf61
|
@ -58,8 +58,9 @@ The app currently has 4 runtime flags:
|
|||||||
- `-o / --logfilepath` -- sets the log output file
|
- `-o / --logfilepath` -- sets the log output file
|
||||||
- `-x / --disable-x-forwarded-for` -- disables checking for the X-Forwarded-For header
|
- `-x / --disable-x-forwarded-for` -- disables checking for the X-Forwarded-For header
|
||||||
- `-l / --allow-private` -- allows lookups of private IP ranges
|
- `-l / --allow-private` -- allows lookups of private IP ranges
|
||||||
|
- `--request-ttl` -- sets the maximum request time to live in seconds
|
||||||
|
|
||||||
All the Flags also have an accompanying environment value: `PROBEHOST_LOGPATH`, `PROBEHOST_ALLOW_PRIVATE`, `PROBEHOST_LISTEN_PORT` and `PROBEHOST_DISABLE_X_FORWARDED_FOR` but the options given via commandline have priority.
|
All the Flags also have an accompanying environment value: `PROBEHOST_LOGPATH`, `PROBEHOST_ALLOW_PRIVATE`, `PROBEHOST_LISTEN_PORT`, `PROBEHOST_DISABLE_X_FORWARDED_FOR` and `PROBEHOST_REQUEST_TTL` but the options given via commandline have priority.
|
||||||
|
|
||||||
The app will log every request including the IP that's querying and show failed requests on stdout.
|
The app will log every request including the IP that's querying and show failed requests on stdout.
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ services:
|
|||||||
- PROBEHOST_ALLOW_PRIVATE=false
|
- PROBEHOST_ALLOW_PRIVATE=false
|
||||||
- PROBEHOST_DISABLE_X_FORWARDED_FOR=false
|
- PROBEHOST_DISABLE_X_FORWARDED_FOR=false
|
||||||
- PROBEHOST_LISTEN_PORT=8000
|
- PROBEHOST_LISTEN_PORT=8000
|
||||||
|
- PROBEHOST_REQUEST_TTL=180
|
||||||
ports:
|
ports:
|
||||||
- 1234:8000
|
- 1234:8000
|
||||||
volumes:
|
volumes:
|
||||||
|
8
go.mod
8
go.mod
@ -2,9 +2,9 @@ module github.com/byReqz/probehost2
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require github.com/sirupsen/logrus v1.8.1
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/sirupsen/logrus v1.9.3
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
github.com/spf13/pflag v1.0.5
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require golang.org/x/sys v0.23.0 // indirect
|
||||||
|
20
go.sum
20
go.sum
@ -1,14 +1,18 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
25
main.go
25
main.go
@ -8,6 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
@ -16,9 +17,10 @@ import (
|
|||||||
var logStdout = log.New()
|
var logStdout = log.New()
|
||||||
var logFile = log.New()
|
var logFile = log.New()
|
||||||
|
|
||||||
var listenPort = 8080 // port to listen on
|
var listenPort = 8080 // port to listen on
|
||||||
var disableXForwardedFor bool // whether to disable parsing the X-Forwarded-For header or not
|
var disableXForwardedFor bool // whether to disable parsing the X-Forwarded-For header or not
|
||||||
var allowPrivate bool // whether to allow private IP ranges or not
|
var allowPrivate bool // whether to allow private IP ranges or not
|
||||||
|
var requestTTL = 180 // maximum request time to live in seconds
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
logStdout.SetFormatter(&log.TextFormatter{
|
logStdout.SetFormatter(&log.TextFormatter{
|
||||||
@ -42,10 +44,19 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val, exists := os.LookupEnv("PROBEHOST_REQUEST_TTL"); exists {
|
||||||
|
var err error
|
||||||
|
requestTTL, err = strconv.Atoi(val)
|
||||||
|
if err != nil {
|
||||||
|
logStdout.Fatal("Failed to read PROBEHOST_REQUEST_TTL: ", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
flag.StringVarP(&logFilePath, "logFilePath", "o", logFilePath, "sets the output file for the log")
|
flag.StringVarP(&logFilePath, "logFilePath", "o", logFilePath, "sets the output file for the log")
|
||||||
flag.IntVarP(&listenPort, "port", "p", listenPort, "sets the port to listen on")
|
flag.IntVarP(&listenPort, "port", "p", listenPort, "sets the port to listen on")
|
||||||
flag.BoolVarP(&disableXForwardedFor, "disable-x-forwarded-for", "x", disableXForwardedFor, "whether to show x-forwarded-for or the requesting IP")
|
flag.BoolVarP(&disableXForwardedFor, "disable-x-forwarded-for", "x", disableXForwardedFor, "whether to show x-forwarded-for or the requesting IP")
|
||||||
flag.BoolVarP(&allowPrivate, "allow-private", "l", allowPrivate, "whether to show lookups of private IP ranges")
|
flag.BoolVarP(&allowPrivate, "allow-private", "l", allowPrivate, "whether to show lookups of private IP ranges")
|
||||||
|
flag.IntVar(&requestTTL, "request-ttl", requestTTL, "sets the maximum request time to live in seconds")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logpath, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0660)
|
logpath, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0660)
|
||||||
@ -84,7 +95,7 @@ func runner(remoteip string, command string, args ...string) string {
|
|||||||
return string(cmd)
|
return string(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validatehosts checks the given host+port combinations for validity and returns valid hosts + valid ports seperately.
|
// validatehosts checks the given host+port combinations for validity and returns valid hosts + valid ports separately.
|
||||||
func validatehosts(hosts []string) ([]string, []string) {
|
func validatehosts(hosts []string) ([]string, []string) {
|
||||||
var validHosts []string
|
var validHosts []string
|
||||||
var validPorts []string
|
var validPorts []string
|
||||||
@ -230,7 +241,13 @@ func main() {
|
|||||||
http.HandleFunc("/tracert/", traceroute)
|
http.HandleFunc("/tracert/", traceroute)
|
||||||
http.HandleFunc("/traceroute/", traceroute)
|
http.HandleFunc("/traceroute/", traceroute)
|
||||||
http.HandleFunc("/nping/", nping)
|
http.HandleFunc("/nping/", nping)
|
||||||
|
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: fmt.Sprint(":", listenPort),
|
||||||
|
ReadHeaderTimeout: time.Duration(requestTTL) * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
logStdout.Info("Serving on :", listenPort)
|
logStdout.Info("Serving on :", listenPort)
|
||||||
logFile.Info("Serving on :", listenPort)
|
logFile.Info("Serving on :", listenPort)
|
||||||
_ = http.ListenAndServe(fmt.Sprint(":", listenPort), nil)
|
_ = server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user