Skip to content

Instantly share code, notes, and snippets.

@gbalbuena
Created August 5, 2013 14:39
Show Gist options
  • Save gbalbuena/6156404 to your computer and use it in GitHub Desktop.
Save gbalbuena/6156404 to your computer and use it in GitHub Desktop.
very simple port scanner in ruby
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