Skip to content

Instantly share code, notes, and snippets.

@mguymon
Created December 8, 2011 17:58
Show Gist options
  • Save mguymon/1447838 to your computer and use it in GitHub Desktop.
Save mguymon/1447838 to your computer and use it in GitHub Desktop.
Simply ruby port knocker
#!/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