Class: SshGuard::FirewallAdapters::IPFWAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_guard/firewall_adapters.rb

Instance Method Summary collapse

Constructor Details

#initializeIPFWAdapter

Returns a new instance of IPFWAdapter.



4
5
6
# File 'lib/ssh_guard/firewall_adapters.rb', line 4

def initialize
  @logger    = Logger.new(STDOUT)
end

Instance Method Details

#block_host(host) ⇒ Object



7
8
9
10
11
12
# File 'lib/ssh_guard/firewall_adapters.rb', line 7

def block_host(host)
  unless blocked?(host)
    `ipfw add 100 deny tcp from #{host} to me ssh`
    @logger.warn("Blocking host #{host}!")
  end
end

#blocked?(host) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ssh_guard/firewall_adapters.rb', line 14

def blocked?(host)
  `ipfw list | grep "deny tcp from #{host} to me dst-port 22"` =~ /deny tcp from #{host} to me dst-port 22$/ ? true : false
end