#!/usr/bin/lua
require 'nixio'
nixio.signal(2,"dfl")
if arg[1]==nil or arg[2]==nil then
	os.exit(1)
end
addr=arg[1]
port=arg[2]
t=5
if arg[3]~=nil then
	t=arg[3]
end
socket=nixio.socket("inet","stream")
socket:setopt("socket","rcvtimeo",t)
socket:setopt("socket","sndtimeo",t)
--print("Detecting ports on server: "..addr..":"..port.."...")
if socket:connect(addr,port) then
	--print("Port open")
	os.exit(0)
else
	--print("Port closed")
	os.exit(1)
end
socket:close()
