require 'socket'
def open_port(host, port) #test whether if the port is open
sock = Socket.new(:INET, :STREAM)
raw = Socket.sockaddr_in(port, host)
puts "#{port} open." if sock.connect(raw)
rescue (Errno::ECONNREFUSED)
end #end of the function
def main(host, start_port, end_port)
start_port =1
if start_port<(end_port/2)
a = Thread.new { loop do
open_port(host,port)
start_port = start_port + 1
if start_port == (end_port/2)
break
end #end of the nearest "if"
end #end of the nearest "loop"
}
a.join
end
if start_port>(end_port/2)
b = Thread.new { loop do
open_port(host,port)
start_port = start_port + 1
if start_port == end_port
break
end #end of the nearest "if"
end #end of the nearest "if"
}
b.join
end
end
main ARGV[0], ARGV[1].to_i, ARGV[2].to_i
哪里出问题了额。。改了半天。。囧