Created
December 8, 2011 17:58
-
-
Save mguymon/1447838 to your computer and use it in GitHub Desktop.
Simply ruby port knocker
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 characters
#!/usr/bin/env ruby | |
require 'socket' | |
require 'timeout' | |
def knock?(ip, port) | |
begin | |
Timeout::timeout(2) do | |
begin | |
s = TCPSocket.new(ip, port) | |
s.close | |
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH | |
end | |
end | |
rescue Timeout::Error | |
end | |
end | |
host = ARGV.shift | |
puts "Knocking #{host} ports #{ARGV.join(' ')}" | |
ARGV.each do|a| | |
knock?( host, a ) | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment