mirror of
https://github.com/nmap/nmap.git
synced 2026-02-05 21:16:33 +00:00
Optimize stdnse.debug and stdnse.verbose
Unnecessary, probably, but this eliminates 2 of 7 string creations/collections due to concatenation and reassignment. Also eliminates 2 unneeded table lookups and tests (since host always has host.ip and port always has port.number), and eliminates 1 extra test for prerule and postrule scripts, since we can't have a port if we don't have a host.
This commit is contained in:
@@ -80,22 +80,11 @@ local function debug (level, ...)
|
||||
end
|
||||
local current = nmap.debugging()
|
||||
if level <= current then
|
||||
local prefix = "["
|
||||
if current >= 2 then
|
||||
prefix = prefix .. (getinfo() or "")
|
||||
else
|
||||
prefix = prefix .. (getid() or "")
|
||||
end
|
||||
local host, port = gethostport()
|
||||
if host and host.ip then
|
||||
prefix = prefix .. " " .. host.ip
|
||||
end
|
||||
if port and port.number then
|
||||
prefix = prefix .. ":" .. port.number
|
||||
end
|
||||
prefix = prefix .. "] "
|
||||
if prefix ~= "[] " then
|
||||
nmap.log_write("stdout", prefix..format(...))
|
||||
local prefix = ( (current >= 2 and getinfo or getid)() or "")
|
||||
.. (host and " "..host.ip .. (port and ":"..port.number or "") or "")
|
||||
if prefix ~= "" then
|
||||
nmap.log_write("stdout", "[" .. prefix .. "] " .. format(...))
|
||||
else
|
||||
nmap.log_write("stdout", format(...))
|
||||
end
|
||||
@@ -148,19 +137,16 @@ local function verbose (level, ...)
|
||||
end
|
||||
local current = nmap.verbosity()
|
||||
if level <= current then
|
||||
local prefix = "[" .. (getid() or "")
|
||||
local prefix
|
||||
if current >= 2 then
|
||||
local host, port = gethostport()
|
||||
if host and host.ip then
|
||||
prefix = prefix .. " " .. host.ip
|
||||
end
|
||||
if port and port.number then
|
||||
prefix = prefix .. ":" .. port.number
|
||||
end
|
||||
prefix = (getid() or "")
|
||||
.. (host and " "..host.ip .. (port and ":"..port.number or "") or "")
|
||||
else
|
||||
prefix = getid() or ""
|
||||
end
|
||||
prefix = prefix .. "] "
|
||||
if prefix ~= "[] " then
|
||||
nmap.log_write("stdout", prefix..format(...))
|
||||
if prefix ~= "" then
|
||||
nmap.log_write("stdout", "[" .. prefix .. "] " .. format(...))
|
||||
else
|
||||
nmap.log_write("stdout", format(...))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user