Class: RedZone::Arpa
- Inherits:
-
Object
- Object
- RedZone::Arpa
- Defined in:
- lib/redzone/arpa.rb
Overview
Arpa definition
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Reverse DNS name.
-
#network ⇒ IPAddr
readonly
Network.
-
#records ⇒ Array<Record>
readonly
Get the list of PTR records.
Instance Method Summary collapse
-
#add(machine, domain) ⇒ Object
Adds a machine to the arpa network for reverse-address lookup only if the machine is in this network.
- #add_record(record) ⇒ Object
-
#initialize(opt) ⇒ Arpa
constructor
Constructs a new MailExchange entry.
-
#write(io) ⇒ Object
Writes the Arpa to the given IO stream.
Constructor Details
#initialize(opt) ⇒ Arpa
Constructs a new MailExchange entry
23 24 25 26 27 28 29 30 31 |
# File 'lib/redzone/arpa.rb', line 23 def initialize(opt) raise ArgumentError, ':name is required' unless opt.has_key?(:name) raise ArgumentError, ':network is required' unless opt.has_key?(:network) raise ArgumentError, ':soa is required' unless opt.has_key?(:soa) @name = opt[:name] @network = IPAddr.new(opt[:network]) @soa = opt[:soa] @records = [] end |
Instance Attribute Details
#name ⇒ String (readonly)
Reverse DNS name
8 9 10 |
# File 'lib/redzone/arpa.rb', line 8 def name @name end |
#network ⇒ IPAddr (readonly)
Network
12 13 14 |
# File 'lib/redzone/arpa.rb', line 12 def network @network end |
#records ⇒ Array<Record> (readonly)
Get the list of PTR records
16 17 18 |
# File 'lib/redzone/arpa.rb', line 16 def records @records end |
Instance Method Details
#add(machine, domain) ⇒ Object
Adds a machine to the arpa network for reverse-address lookup only if the machine is in this network.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/redzone/arpa.rb', line 47 def add(machine,domain) fqdn = "#{machine.name}.#{domain}." substr = ".#{@name}" if @network.ipv4? and machine.ipv4? and @network.include?(machine.ipv4) ip = machine.ipv4.reverse ip.slice!(substr) records << Record.new(:name => ip, :type => "PTR", :data => fqdn, :comment => "Machine #{machine.name}") end if @network.ipv6? and machine.ipv6? and @network.include?(machine.ipv6) ip = machine.ipv6.ip6_arpa ip.slice!(substr) records << Record.new(:name => ip, :type => "PTR", :data => fqdn, :comment => "Machine #{machine.name}") end end |
#add_record(record) ⇒ Object
62 63 64 |
# File 'lib/redzone/arpa.rb', line 62 def add_record(record) records << record end |
#write(io) ⇒ Object
Writes the Arpa to the given IO stream
35 36 37 38 39 40 41 |
# File 'lib/redzone/arpa.rb', line 35 def write(io) io << @soa @records.each do |r| io << r end io << "\n" end |