1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-06 14:39:03 +00:00

Small cleanup for irc-info.nse

This commit is contained in:
dmiller
2017-07-28 04:03:57 +00:00
parent 95bab11f92
commit 2a5b464158

View File

@@ -1,5 +1,6 @@
local comm = require "comm"
local nmap = require "nmap"
local math = require "math"
local irc = require "irc"
local stdnse = require "stdnse"
@@ -52,17 +53,15 @@ local function random_nick ()
end
function action (host, port)
local sd = nmap.new_socket()
local nick = random_nick()
local output = stdnse.output_table()
local sd, line = comm.tryssl(host, port, "USER nmap +iw nmap :Nmap Wuz Here\nNICK " .. nick .. "\n")
local sd, line = comm.tryssl(host, port,
("USER nmap +iw nmap :Nmap Wuz Here\nNICK %s\n"):format(nick),
{request_timeout=6000})
if not sd then return "Unable to open connection" end
-- set a healthy banner timeout
sd:set_timeout(banner_timeout * 1000)
local buf = stdnse.make_buffer(sd, "\r?\n")
while line do
@@ -90,12 +89,6 @@ function action (host, port)
sd:send("NICK " .. nick .. "\n")
end
info = line:match "^:([%w-_.]+) 433"
if info then
nick = random_nick()
sd:send("NICK " .. nick .. "\n")
end
-- PING/PONG
local dummy = line:match "^PING :(.*)"
if dummy then
@@ -111,7 +104,7 @@ function action (host, port)
-- Various bits of info
local users, invisible, servers = line:match "^:[%w-_.]+ 251 %w+ :There are (%d+) users and (%d+) invisible on (%d+) servers"
if users then
output.users = users + invisible
output.users = math.tointeger(users + invisible)
output.servers = servers
end