Created
March 30, 2012 08:16
-
-
Save kano4/2249392 to your computer and use it in GitHub Desktop.
Port Scanner with timeout method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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