Skip to content

Instantly share code, notes, and snippets.

@kano4
Created March 30, 2012 08:16
Show Gist options
  • Save kano4/2249392 to your computer and use it in GitHub Desktop.
Save kano4/2249392 to your computer and use it in GitHub Desktop.
Port Scanner with timeout method.
require 'timeout'
require 'socket'
puts "Enter IP Address to Scan:"
ipaddress = gets
1.upto(1024) {|port|
begin
timeout(5) do
TCPSocket.open(ipaddress.chop, port)
end
puts "Response/Port Open: #{port}"
rescue Timeout::Error
# uncomment the following line to show closed ports (noisy!)
#puts "No Response / Port closed: #{port}"
rescue
# uncomment the following line to show closed ports (noisy!)
#puts "No Response / Port closed: #{port}"
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment