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) {
|
||||
var ret IPInfoResponse
|
||||
var err error
|
||||
|
||||
if r.RawISPInfo != "" {
|
||||
err = json.Unmarshal([]byte(r.RawISPInfo), &ret)
|
||||
} else {
|
||||
|
|
39
web/web.go
39
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue