From fed9b40c86a04aacf1469f4b4a4e94bded922a8c Mon Sep 17 00:00:00 2001 From: Nils Date: Tue, 28 Dec 2021 04:02:54 +0100 Subject: [PATCH] add traceroute --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index cdb83b6..9b8b21f 100644 --- a/main.go +++ b/main.go @@ -106,9 +106,25 @@ func mtr(w http.ResponseWriter, req *http.Request) { } } +func traceroute(w http.ResponseWriter, req *http.Request) { + geturl := strings.Split(req.URL.String(), "/") + targets := strings.Split(geturl[2], ",") + hosts := validatehosts(targets) + var res string + for _, host := range hosts { + res = fmt.Sprint(res, runner(req.RemoteAddr, "traceroute", host), "\n") + } + if res == "" { + fmt.Fprintln(w, http.StatusInternalServerError) + } else { + fmt.Fprint(w, strings.TrimSpace(res), "\n") + } +} + func main() { http.HandleFunc("/ping/", ping) http.HandleFunc("/mtr/", mtr) + http.HandleFunc("/tracert/", traceroute) logstdout.Info("Serving on :", listenport) logfile.Info("Serving on :", listenport) http.ListenAndServe(fmt.Sprint(":", listenport), nil)