1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Adds protection against incomplete GeoPlugin results, such as 92.123.145.37. Fixes #1331

This commit is contained in:
nnposter
2018-10-09 00:15:07 +00:00
parent 466bf8ff65
commit 74f1b37ff2
2 changed files with 15 additions and 4 deletions

View File

@@ -1,5 +1,8 @@
#Nmap Changelog ($Id$); -*-text-*-
o [NSE][GH#1331] Script traceroute-geolocation no longer crashes when
www.GeoPlugin.net returns null coordinates [Michal Kubenka, nnposter]
o Limit verbose -v and debugging -d levels to a maximum of 10. Nmap does not
use higher levels internally. [Daniel Miller]

View File

@@ -87,13 +87,21 @@ local function geoLookup(ip, no_cache)
local response = http.get("www.geoplugin.net", 80, "/json.gp?ip="..ip, {any_af=true})
local stat, loc = json.parse(response.body)
if not stat then return nil end
local regionName = (loc.geoplugin_regionName == json.NULL) and "Unknown" or loc.geoplugin_regionName
local get_value = function (d)
local t = type(d)
return (t == "string" or t == "number") and d or nil
end
if not (stat
and get_value(loc.geoplugin_latitude)
and get_value(loc.geoplugin_longitude)) then
return nil
end
output = {
lat = loc.geoplugin_latitude,
lon = loc.geoplugin_longitude,
reg = regionName,
ctry = loc.geoplugin_countryName
reg = get_value(loc.geoplugin_regionName) or "Unknown",
ctry = get_value(loc.geoplugin_countryName) or "Unknown"
}
if not no_cache then
stdnse.registry_add_table({SCRIPT_NAME}, ip, output)