Class: IP::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/iptable/ip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Rule

Returns a new instance of Rule.



116
117
118
119
120
121
122
123
# File 'lib/iptable/ip.rb', line 116

def initialize(options)
  @chain = options[:chain]
  raise "Rule needs a chain" unless @chain
  @packets = options[:packets].to_i
  @target = nil
  @dport = options[:dport]
  @protocol = options[:protocol] || "all"
end

Instance Attribute Details

#chainObject

Returns the value of attribute chain.



113
114
115
# File 'lib/iptable/ip.rb', line 113

def chain
  @chain
end

#packetsObject (readonly)

Returns the value of attribute packets.



114
115
116
# File 'lib/iptable/ip.rb', line 114

def packets
  @packets
end

#targetObject

Returns the value of attribute target.



113
114
115
# File 'lib/iptable/ip.rb', line 113

def target
  @target
end

Instance Method Details

#saveObject



125
126
127
128
129
# File 'lib/iptable/ip.rb', line 125

def save
  IO.popen("/sbin/iptables -A #{@chain.name} -p #{@protocol} --dport #{@dport}") do |output|
    puts output.read
  end
end