Sha256: 6472a6a4410fb1879d5cdd06dfde70e23b6b2fe9bfac03e152defcf4cf9e8b6f

Contents?: true

Size: 783 Bytes

Versions: 25

Compression:

Stored size: 783 Bytes

Contents

module LinuxAdmin
  class Dns
    attr_accessor :filename
    attr_accessor :nameservers
    attr_accessor :search_order

    def initialize(filename = "/etc/resolv.conf")
      @filename = filename
      reload
    end

    def reload
      @search_order = []
      @nameservers  = []

      File.read(@filename).split("\n").each do |line|
        if line =~ /^search .*/
          @search_order += line.split(/^search\s+/)[1].split
        elsif line =~ /^nameserver .*/
          @nameservers.push(line.split[1])
        end
      end
    end

    def save
      search  = "search #{@search_order.join(" ")}\n" unless @search_order.empty?
      servers = @nameservers.collect { |ns| "nameserver #{ns}\n" }.join
      File.write(@filename, "#{search}#{servers}")
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
linux_admin-4.0.0 lib/linux_admin/dns.rb
linux_admin-3.0.0 lib/linux_admin/dns.rb
linux_admin-2.0.2 lib/linux_admin/dns.rb
linux_admin-2.0.1 lib/linux_admin/dns.rb
linux_admin-2.0.0 lib/linux_admin/dns.rb
linux_admin-1.2.4 lib/linux_admin/dns.rb
linux_admin-1.2.3 lib/linux_admin/dns.rb
linux_admin-1.2.2 lib/linux_admin/dns.rb
linux_admin-1.2.1 lib/linux_admin/dns.rb
linux_admin-1.0.1 lib/linux_admin/dns.rb
linux_admin-1.2.0 lib/linux_admin/dns.rb
linux_admin-1.1.0 lib/linux_admin/dns.rb
linux_admin-1.0.0 lib/linux_admin/dns.rb
linux_admin-0.20.2 lib/linux_admin/dns.rb
linux_admin-0.20.1 lib/linux_admin/dns.rb
linux_admin-0.20.0 lib/linux_admin/dns.rb
linux_admin-0.19.0 lib/linux_admin/dns.rb
linux_admin-0.18.0 lib/linux_admin/dns.rb
linux_admin-0.17.0 lib/linux_admin/dns.rb
linux_admin-0.16.0 lib/linux_admin/dns.rb