diff --git a/results/telemetry.go b/results/telemetry.go index cefba4b..886ab93 100644 --- a/results/telemetry.go +++ b/results/telemetry.go @@ -132,6 +132,7 @@ func init() { func (r *Result) GetISPInfo() (IPInfoResponse, error) { var ret IPInfoResponse var err error + if r.RawISPInfo != "" { err = json.Unmarshal([]byte(r.RawISPInfo), &ret) } else { diff --git a/web/web.go b/web/web.go index 54e2117..2f388fe 100644 --- a/web/web.go +++ b/web/web.go @@ -154,25 +154,32 @@ func getIP(w http.ResponseWriter, r *http.Request) { return } - rawIspInfo, ispInfo := getIPInfo(clientIP) - ret.RawISPInfo = rawIspInfo + getISPInfo := r.FormValue("isp") == "true" + getDistance := r.FormValue("distance") == "true" - removeRegexp := regexp.MustCompile(`AS\d+\s`) - isp := removeRegexp.ReplaceAllString(ispInfo.Organization, "") + ret.ProcessedString = clientIP - if isp == "" { - isp = "Unknown ISP" + if getISPInfo { + rawIspInfo, ispInfo := getIPInfo(clientIP) + ret.RawISPInfo = rawIspInfo + + removeRegexp := regexp.MustCompile(`AS\d+\s`) + isp := removeRegexp.ReplaceAllString(ispInfo.Organization, "") + + if isp == "" { + isp = "Unknown ISP" + } + + if ispInfo.Country != "" { + isp += ", " + ispInfo.Country + } + + if ispInfo.Location != "" && getDistance { + isp += " (" + calculateDistance(ispInfo.Location, config.LoadedConfig().DistanceUnit) + ")" + } + + ret.ProcessedString += " - " + isp } - if ispInfo.Country != "" { - isp += ", " + ispInfo.Country - } - - if ispInfo.Location != "" { - isp += " (" + calculateDistance(ispInfo.Location, config.LoadedConfig().DistanceUnit) + ")" - } - - ret.ProcessedString = clientIP + " - " + isp - render.JSON(w, r, ret) }