Module: RubyDNS::System

Defined in:
lib/rubydns/system.rb

Overview

This module encapsulates system dependent name lookup functionality.

Defined Under Namespace

Classes: Hosts

Constant Summary collapse

RESOLV_CONF =
"/etc/resolv.conf"
HOSTS =
"/etc/hosts"

Class Method Summary collapse

Class Method Details

.hosts_pathObject



33
34
35
36
37
38
39
# File 'lib/rubydns/system.rb', line 33

def self.hosts_path
	if RUBY_PLATFORM =~ /mswin32|mingw|bccwin/
		Win32::Resolv.get_hosts_path
	else
		HOSTS
	end
end

.nameserversObject

Get a list of standard nameserver connections which can be used for querying any standard servers that the system has been configured with. There is no equivalent facility to use the hosts file at present.



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rubydns/system.rb', line 134

def self.nameservers
	nameservers = []

	if File.exist? RESOLV_CONF
		nameservers = parse_resolv_configuration(RESOLV_CONF)
	elsif defined?(Win32::Resolv) and RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
		search, nameservers = Win32::Resolv.get_resolv_info
	end

	return standard_connections(nameservers)
end

.parse_resolv_configuration(path) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rubydns/system.rb', line 102

def self.parse_resolv_configuration(path)
	nameservers = []
	File.open(path) do |file|
		file.each do |line|
			# Remove any comments:
			line.sub!(/[#;].*/, '')

			# Extract resolv.conf command:
			keyword, *args = line.split(/\s+/)

			case keyword
			when 'nameserver'
				nameservers += args
			end
		end
	end

	return nameservers
end

.standard_connections(nameservers) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/rubydns/system.rb', line 122

def self.standard_connections(nameservers)
	connections = []

	nameservers.each do |host|
		connections << [:udp, host, 53]
		connections << [:tcp, host, 53]
	end

	return connections
end