Class: EventMachine::DNS::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/em/resolver.rb

Class Method Summary collapse

Class Method Details

.hostsObject



51
52
53
# File 'lib/em/resolver.rb', line 51

def self.hosts
  @hosts
end

.nameserverObject



47
48
49
# File 'lib/em/resolver.rb', line 47

def self.nameserver
  nameservers.shuffle.first
end

.nameserversObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/em/resolver.rb', line 35

def self.nameservers
  if !@nameservers
    @nameservers = []
    IO.readlines('/etc/resolv.conf').each do |line|
      if line =~ /^nameserver (.+)$/
        @nameservers << $1.split(/\s+/).first
      end
    end
  end
  @nameservers
end

.nameservers=(ns) ⇒ Object



31
32
33
# File 'lib/em/resolver.rb', line 31

def self.nameservers=(ns)
  @nameservers = ns
end

.resolve(hostname) ⇒ Object



5
6
7
# File 'lib/em/resolver.rb', line 5

def self.resolve(hostname)
  Request.new(socket, hostname)
end

.socketObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/em/resolver.rb', line 11

def self.socket
  if !@socket || (@socket && @socket.error?)
    @socket = Socket.open

    @hosts  = {}
    IO.readlines('/etc/hosts').each do |line|
      next if line =~ /^#/
      addr, host = line.split(/\s+/)

      if @hosts[host]
        @hosts[host] << addr
      else
        @hosts[host] = [addr]
      end
    end
  end

  @socket
end