I've wrote the following script in Lua to be used with nmap:
action = function()
local target = "46.121.76.117"
local sock = nmap.new_socket("tcp")
sock:set_timeout(10)
local status, err = sock:connect(target, 17)
if not status then
-- Failed to connect
stdnse.debug1("Couldn't connect to %s on port %d; %s",target, 17, err)
sock:close()
return
end
The problem is that the script doesn't wait 1 second and prints immediately:
Couldn't connect to 46.121.76.117 on port 17; TIMEOUT
Why is that?
I ran nmap 46.121.76.117
and it shows port 17
as Open.
As mentioned in the comments, set_timeout
sets the timeout value in milliseconds, so if you want to set it to 10 seconds, you need to call set_timeout(10*1000)
. This most likely explains the results you see with the client resetting the connection after 10ms.