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:
@@ -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]
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user