1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 22:21:29 +00:00

Fix geoip.get_all_by_gps limiting by moving to the Bing script. Fixes #616

This commit is contained in:
dmiller
2016-12-18 20:11:14 +00:00
parent c1dac8a37f
commit 0f67084fb3
3 changed files with 19 additions and 9 deletions

View File

@@ -55,17 +55,13 @@ end
--- Retrieve a table of IPs by coordinate
--@return A table of IPs keyed by coordinate in <code>lat,lon</code> format
get_all_by_gps = function(limit)
get_all_by_gps = function()
if empty() then
return nil
end
local t = {}
for ip, coords in pairs(get_all_by_ip()) do
if limit and limit < #t then
break
end
local key = coords["latitude"] .. "," .. coords["longitude"]
if not t[key] then
t[key] = {}

View File

@@ -11,6 +11,9 @@ This script queries the Nmap registry for the GPS coordinates of targets stored
by previous geolocation scripts and renders a Bing Map of markers representing
the targets.
The Bing Maps REST API has a limit of 100 markers, so if more coordinates are
found, only the top 100 markers by number of IPs will be shown.
Additional information for the Bing Maps REST Services API can be found at:
- https://msdn.microsoft.com/en-us/library/ff701724.aspx
]]
@@ -63,10 +66,21 @@ local render = function(params, options)
-- Add in a marker for each host.
local markers = {}
for coords, ip in pairs(geoip.get_all_by_gps(100)) do
table.insert(markers, "pp=" .. coords .. style)
for coords, ip in pairs(geoip.get_all_by_gps()) do
table.insert(markers, {#ip, "pp=" .. coords .. style})
end
local body = table.concat(markers, "&")
if #markers > 100 then
-- API is limited to 100 markers
stdnse.verbose1("Bing Maps API limits render to 100 markers. Some results not mapped.")
-- sort by number of IPs so we map the biggest groups
table.sort(markers, function (a, b) return a[1] < b[1] end)
end
local out_markers = {}
for i=1, #markers do
if i > 100 then break end
out_markers[#out_markers+1] = markers[i][2]
end
local body = table.concat(out_markers, "&")
-- Format the parameters into a properly encoded URL.
local query = "/REST/v1/Imagery/Map/" .. options["layer"] .. "?" .. url.build_query(params)

View File

@@ -24,7 +24,7 @@ Additional information for the Google Static Maps API can be found at:
--
-- @args ip-geolocation-map-google.api_key The required Google Maps API key for
-- your account. An API key can be generated at
-- https://developers.google.com/maps/documentation/static-maps/."
-- https://developers.google.com/maps/documentation/static-maps/
--
-- @args ip-geolocation-map-google.center GPS coordinates defining the center of the
-- image. If omitted, Google Maps will choose a center that shows all the