Class: Netfilter::IpTables

Inherits:
Tool
  • Object
show all
Defined in:
lib/netfilter/ip_tables.rb

Direct Known Subclasses

Ip6Tables

Instance Attribute Summary

Attributes inherited from Tool

#namespace, #tables

Class Method Summary collapse

Methods inherited from Tool

#commands, delete_chain, #down, executable, #executable, execute, #export, import, #initialize, #pp, #table, #up

Constructor Details

This class inherits a constructor from Netfilter::Tool

Class Method Details

.parseObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/netfilter/ip_tables.rb', line 4

def self.parse
  {}.tap do |data|
    string = execute("#{executable}-save").strip << "\n"
    string = string.split("\n").reject{ |s| s[0] == "#" }.join("\n")
    string.split(/^\*/).select{ |s| s != "" }.each do |string|
      table, string = string.match(/(.+?)\n(.*)/m).to_a[1..-1]
      data[table] = {}

      string.scan(/^:(.+?)\s+/).each do |match|
        data[table][match[0]] = []
      end

      string.scan(/^-A (.+?) (.+?)\n/).each do |match|
        data[table][match[0]] << match[1]
      end
    end
  end
end