Support isp and distance query params on getIP
This commit is contained in:
parent
687a5aeca0
commit
79b4c54770
|
@ -132,6 +132,7 @@ func init() {
|
||||||
func (r *Result) GetISPInfo() (IPInfoResponse, error) {
|
func (r *Result) GetISPInfo() (IPInfoResponse, error) {
|
||||||
var ret IPInfoResponse
|
var ret IPInfoResponse
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if r.RawISPInfo != "" {
|
if r.RawISPInfo != "" {
|
||||||
err = json.Unmarshal([]byte(r.RawISPInfo), &ret)
|
err = json.Unmarshal([]byte(r.RawISPInfo), &ret)
|
||||||
} else {
|
} else {
|
||||||
|
|
39
web/web.go
39
web/web.go
|
@ -154,25 +154,32 @@ func getIP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rawIspInfo, ispInfo := getIPInfo(clientIP)
|
getISPInfo := r.FormValue("isp") == "true"
|
||||||
ret.RawISPInfo = rawIspInfo
|
getDistance := r.FormValue("distance") == "true"
|
||||||
|
|
||||||
removeRegexp := regexp.MustCompile(`AS\d+\s`)
|
ret.ProcessedString = clientIP
|
||||||
isp := removeRegexp.ReplaceAllString(ispInfo.Organization, "")
|
|
||||||
|
|
||||||
if isp == "" {
|
if getISPInfo {
|
||||||
isp = "Unknown ISP"
|
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)
|
render.JSON(w, r, ret)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue