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

Don't randomly select the servers to show. Just show the ones at the

top. Display the total number when limiting output.
This commit is contained in:
david
2011-02-22 21:55:25 +00:00
parent e5717f259a
commit 1c4e060f79

View File

@@ -120,28 +120,22 @@ local function getservers(host, port, q3protocol)
end
local function formatresult(servers, outputlimit, protocols)
math.randomseed(os.time())
randomized = {}
while #servers > 0 do
local x = table.remove(servers, math.random(1, #servers))
table.insert(randomized, x)
end
if not outputlimit then
outputlimit = #randomized
outputlimit = #servers
end
local formatted = {}
for i = 1, outputlimit do
if not randomized[i] then
if not servers[i] then
break
end
local node = randomized[i]
local node = servers[i]
local protocol = node.protocol
local ip = node.ip
local portnum = node.port
table.insert(formatted, string.format('%s:%d %s (%s)', ip, portnum, protocols[protocol], protocol))
end
if #formatted < #randomized then
table.insert(formatted, string.format('Only %d shown. Use --script-args %s.outputlimit=-1 to see all.', outputlimit, SCRIPT_NAME))
if #formatted < #servers then
table.insert(formatted, string.format('Only %d/%d shown. Use --script-args %s.outputlimit=-1 to see all.', #formatted, #servers, SCRIPT_NAME))
end
return formatted
end