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

Move format_difftime to after the action function where it belongs.

This commit is contained in:
david
2009-07-13 22:49:50 +00:00
parent 40b0f784e7
commit 7ce852170b

View File

@@ -23,6 +23,28 @@ require("shortport")
portrule = shortport.port_or_service({80, 443, 631, 8080},
{"http", "https", "ipp", "http-alt"})
local format_difftime
action = function(host, port)
-- Get the local date in UTC.
local request_date = os.date("!*t")
local response = http.get(host, port, "/")
if not response.status or not response.header["date"] then
return
end
local response_date = http.parse_date(response.header["date"])
if not response_date then
return
end
-- Should account for estimated RTT too.
local diff = format_difftime(response_date, request_date)
return string.format("%s; %s from local time.",
response.header["date"], diff)
end
-- Turn a positive or negative number of seconds into a string in one of the
-- forms. Signs can of course vary.
-- 0s
@@ -31,7 +53,7 @@ portrule = shortport.port_or_service({80, 443, 631, 8080},
-- -9h12m34s
-- +5d17h05m06s
-- -2y177d10h13m20s
local function format_difftime(t2, t1)
format_difftime = function(t2, t1)
local d, s, sign, yeardiff
d = os.difftime(os.time(t2), os.time(t1))
@@ -90,23 +112,3 @@ local function format_difftime(t2, t1)
s = string.format("%dy", yeardiff) .. s
return sign .. s
end
action = function(host, port)
-- Get the local date in UTC.
local request_date = os.date("!*t")
local response = http.get(host, port, "/")
if not response.status or not response.header["date"] then
return
end
local response_date = http.parse_date(response.header["date"])
if not response_date then
return
end
-- Should account for estimated RTT too.
local diff = format_difftime(response_date, request_date)
return string.format("%s; %s from local time.",
response.header["date"], diff)
end