Created
August 5, 2013 14:39
-
-
Save gbalbuena/6156404 to your computer and use it in GitHub Desktop.
very simple port scanner in ruby
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 'socket' #socket library | |
def open_port(host, port) | |
sock = Socket.new(:INET, :STREAM) | |
raw = Socket.sockaddr_in(port, host) | |
puts "#{port} open." if sock.connect(raw) | |
rescue (Errno::ECONNREFUSED) | |
rescue(Errno::ETIMEDOUT) | |
end | |
def main(host, start_port, end_port) | |
until start_port == end_port do | |
open_port(host, start_port) | |
start_port += 1 | |
end | |
end | |
main ARGV[0], ARGV[1].to_i, ARGV[2].to_i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment