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:
@@ -55,17 +55,13 @@ end
|
|||||||
|
|
||||||
--- Retrieve a table of IPs by coordinate
|
--- Retrieve a table of IPs by coordinate
|
||||||
--@return A table of IPs keyed by coordinate in <code>lat,lon</code> format
|
--@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
|
if empty() then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local t = {}
|
local t = {}
|
||||||
for ip, coords in pairs(get_all_by_ip()) do
|
for ip, coords in pairs(get_all_by_ip()) do
|
||||||
if limit and limit < #t then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
local key = coords["latitude"] .. "," .. coords["longitude"]
|
local key = coords["latitude"] .. "," .. coords["longitude"]
|
||||||
if not t[key] then
|
if not t[key] then
|
||||||
t[key] = {}
|
t[key] = {}
|
||||||
|
|||||||
@@ -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
|
by previous geolocation scripts and renders a Bing Map of markers representing
|
||||||
the targets.
|
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:
|
Additional information for the Bing Maps REST Services API can be found at:
|
||||||
- https://msdn.microsoft.com/en-us/library/ff701724.aspx
|
- 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.
|
-- Add in a marker for each host.
|
||||||
local markers = {}
|
local markers = {}
|
||||||
for coords, ip in pairs(geoip.get_all_by_gps(100)) do
|
for coords, ip in pairs(geoip.get_all_by_gps()) do
|
||||||
table.insert(markers, "pp=" .. coords .. style)
|
table.insert(markers, {#ip, "pp=" .. coords .. style})
|
||||||
end
|
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.
|
-- Format the parameters into a properly encoded URL.
|
||||||
local query = "/REST/v1/Imagery/Map/" .. options["layer"] .. "?" .. url.build_query(params)
|
local query = "/REST/v1/Imagery/Map/" .. options["layer"] .. "?" .. url.build_query(params)
|
||||||
|
|||||||
@@ -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
|
-- @args ip-geolocation-map-google.api_key The required Google Maps API key for
|
||||||
-- your account. An API key can be generated at
|
-- 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
|
-- @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
|
-- image. If omitted, Google Maps will choose a center that shows all the
|
||||||
|
|||||||
Reference in New Issue
Block a user