Skip to content

Instantly share code, notes, and snippets.

@toretore
Forked from anonymous/gist:d269e30f3e45aae37780
Last active August 29, 2015 14:02
Show Gist options
  • Save toretore/38eaeed4884283e9c2ed to your computer and use it in GitHub Desktop.
Save toretore/38eaeed4884283e9c2ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'socket'
require 'thread'
threads = Array.new
ports = [*(1..1024)]
mutex = Mutex.new
20.times do
threads << Thread.new do |p|
while port = mutex.synchronize{ ports.pop }
begin
t = TCPSocket.new("myserver.net", p).close
puts "PORT #{p} OPEN"
rescue
puts "PORT #{p} CLOSED"
end
end
end
end
threads.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment