1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-08 06:26:33 +00:00

Update several scripts and libraries to use stdnse.format_time

This commit is contained in:
dmiller
2014-09-05 02:54:39 +00:00
parent 6dfd1b5abe
commit 33adefaab6
5 changed files with 7 additions and 74 deletions

View File

@@ -80,25 +80,6 @@ local function getOrderPos(tag)
return 1
end
local function minutesToUptime(value)
local days = math.floor(value / (60 * 24))
local htime = math.fmod(value, (60 * 24))
local hours = math.floor(htime / 60)
local mtime = math.fmod(htime, 60)
local minutes = math.floor(mtime)
local output = ""
if ( days > 0 ) then
output = output .. ("%d days, "):format(days)
end
if ( hours > 0 ) then
output = output .. ("%d hours, "):format(hours)
end
if ( minutes > 0 ) then
output = output .. ("%d minutes"):format(minutes)
end
return output
end
local function decodeTag(tag, lines)
local result = { name = long_names[tag] }
local order
@@ -131,7 +112,7 @@ local function decodeTag(tag, lines)
"version" == tag ) then
return ("%s: %s"):format(long_names[tag], lines[1])
elseif ( "uptime" == tag ) then
return ("%s: %s"):format(long_names[tag], minutesToUptime(lines[1]))
return ("%s: %s"):format(long_names[tag], stdnse.format_time(lines[1] * 60))
elseif ( "mem" == tag ) then
local total, used = table.unpack(stdnse.strsplit("%s", lines[1]))
if ( not(total) or not(used) ) then

View File

@@ -304,23 +304,15 @@ action = function(host)
local time = sessions[i]['time']
if(time == 0) then
time = "[just logged in, it's probably you]"
elseif(time > 60 * 60 * 24) then
time = string.format("%dd%dh%02dm%02ds", time / (60*60*24), (time % (60*60*24)) / 3600, (time % 3600) / 60, time % 60)
elseif(time > 60 * 60) then
time = string.format("%dh%02dm%02ds", time / 3600, (time % 3600) / 60, time % 60)
else
time = string.format("%02dm%02ds", time / 60, time % 60)
time = stdnse.format_time(time)
end
local idle_time = sessions[i]['idle_time']
if(idle_time == 0) then
idle_time = "[not idle]"
elseif(idle_time > 60 * 60 * 24) then
idle_time = string.format("%dd%dh%02dm%02ds", idle_time / (60*60*24), (idle_time % (60*60*24)) / 3600, (idle_time % 3600) / 60, idle_time % 60)
elseif(idle_time > 60 * 60) then
idle_time = string.format("%dh%02dm%02ds", idle_time / 3600, (idle_time % 3600) / 60, idle_time % 60)
else
idle_time = string.format("%02dm%02ds", idle_time / 60, idle_time % 60)
idle_time = stdnse.format_time(idle_time)
end
table.insert(sessions_output, string.format("%s is connected from %s for %s, idle for %s", sessions[i]['user'], sessions[i]['client'], time, idle_time))

View File

@@ -1,8 +1,8 @@
local math = require "math"
local nmap = require "nmap"
local shortport = require "shortport"
local snmp = require "snmp"
local string = require "string"
local stdnse = require "stdnse"
description = [[
Attempts to extract system information from an SNMP version 1 service.
@@ -97,24 +97,7 @@ action = function(host, port)
return
end
local days, hours, minutes, seconds, htime, mtime, stime
days = math.floor(uptime / 8640000)
htime = math.fmod(uptime, 8640000)
hours = math.floor(htime / 360000)
mtime = math.fmod(htime, 360000)
minutes = math.floor(mtime / 6000)
stime = math.fmod(mtime, 6000)
seconds = stime / 100
local dayLabel
if days == 1 then
dayLabel = "day"
else
dayLabel = "days"
end
result = result .. "\n" .. string.format(" System uptime: %d %s, %d:%02d:%05.2f (%s timeticks)", days, dayLabel, hours, minutes, seconds, tostring(uptime))
result = result .. "\n" .. string.format(" System uptime: %s (%s timeticks)", stdnse.format_time(uptime, 100), tostring(uptime))
return result
end