Created
August 1, 2013 17:36
-
-
Save turboladen/6133524 to your computer and use it in GitHub Desktop.
Revisions
-
turboladen created this gist
Aug 1, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ # Thanks to http://rubysource.com/build-a-port-scanner-in-ruby require 'celluloid' require 'socket' class ScanPort include Celluloid def initialize(start_port, end_port, host) @start_port = start_port @end_port = end_port @host = host end def run until @start_port == @end_port do scan @start_port @start_port += 1 end end def scan(port) begin sock = TCPSocket.new(@host, port) puts "#{port} open." if sock rescue => ex p ex unless ex.is_a?(Errno::ECONNREFUSED) ensure sock.close if sock end end end def main host = ARGV[0] start_port = ARGV[1].to_i end_port = ARGV[2].to_i segment_size = 100 until start_port >= end_port do sp = ScanPort.new start_port, start_port + segment_size, host sp.async.run start_port += segment_size end end main