Class: Resolv

Inherits:
Object
  • Object
show all
Defined in:
lib/net/dns/resolv.rb,
lib/net/dns/resolvx.rb,
lib/net/dns/resolvx.rb,
lib/net/dns/resolvx.rb,
lib/net/dns/resolvx.rb,
lib/net/dns/resolvx.rb,
lib/net/dns/resolvx.rb,
lib/net/dns/resolv-mdns.rb

Defined Under Namespace

Classes: DNS, Hosts, IPv4, IPv6, MDNS, ResolvError, ResolvTimeout

Constant Summary collapse

DefaultResolver =
self.new
AddressRegex =
/(?:#{IPv4::Regex})|(?:#{IPv6::Regex})/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resolvers = [Hosts.new, DNS.new]) ⇒ Resolv

Returns a new instance of Resolv.



267
268
269
# File 'lib/net/dns/resolv.rb', line 267

def initialize(resolvers=[Hosts.new, DNS.new])
  @resolvers = resolvers
end

Instance Attribute Details

#resolversObject (readonly)

The resolvers configured.



37
38
39
# File 'lib/net/dns/resolvx.rb', line 37

def resolvers
  @resolvers
end

Class Method Details

.default_resolversObject

The default resolvers.



32
33
34
# File 'lib/net/dns/resolvx.rb', line 32

def self.default_resolvers
  DefaultResolver.resolvers
end

.each_address(name, &block) ⇒ Object



251
252
253
# File 'lib/net/dns/resolv.rb', line 251

def self.each_address(name, &block)
  DefaultResolver.each_address(name, &block)
end

.each_name(address, &proc) ⇒ Object



263
264
265
# File 'lib/net/dns/resolv.rb', line 263

def self.each_name(address, &proc)
  DefaultResolver.each_name(address, &proc)
end

.getaddress(name) ⇒ Object



243
244
245
# File 'lib/net/dns/resolv.rb', line 243

def self.getaddress(name)
  DefaultResolver.getaddress(name)
end

.getaddresses(name) ⇒ Object



247
248
249
# File 'lib/net/dns/resolv.rb', line 247

def self.getaddresses(name)
  DefaultResolver.getaddresses(name)
end

.getname(address) ⇒ Object



255
256
257
# File 'lib/net/dns/resolv.rb', line 255

def self.getname(address)
  DefaultResolver.getname(address)
end

.getnames(address) ⇒ Object



259
260
261
# File 'lib/net/dns/resolv.rb', line 259

def self.getnames(address)
  DefaultResolver.getnames(address)
end

Instance Method Details

#each_address(name) ⇒ Object



282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/net/dns/resolv.rb', line 282

def each_address(name)
  if AddressRegex =~ name
    yield name
    return
  end
  yielded = false
  @resolvers.each {|r|
    r.each_address(name) {|address|
      yield address.to_s
      yielded = true
    }
    return if yielded
  }
end

#each_name(address) ⇒ Object



308
309
310
311
312
313
314
315
316
317
# File 'lib/net/dns/resolv.rb', line 308

def each_name(address)
  yielded = false
  @resolvers.each {|r|
    r.each_name(address) {|name|
      yield name.to_s
      yielded = true
    }
    return if yielded
  }
end

#getaddress(name) ⇒ Object

Raises:



271
272
273
274
# File 'lib/net/dns/resolv.rb', line 271

def getaddress(name)
  each_address(name) {|address| return address}
  raise ResolvError.new("no address for #{name}")
end

#getaddresses(name) ⇒ Object



276
277
278
279
280
# File 'lib/net/dns/resolv.rb', line 276

def getaddresses(name)
  ret = []
  each_address(name) {|address| ret << address}
  return ret
end

#getname(address) ⇒ Object

Raises:



297
298
299
300
# File 'lib/net/dns/resolv.rb', line 297

def getname(address)
  each_name(address) {|name| return name}
  raise ResolvError.new("no name for #{address}")
end

#getnames(address) ⇒ Object



302
303
304
305
306
# File 'lib/net/dns/resolv.rb', line 302

def getnames(address)
  ret = []
  each_name(address) {|name| ret << name}
  return ret
end