Class: Ddig::Resolver::Do53
- Inherits:
-
Object
- Object
- Ddig::Resolver::Do53
- Defined in:
- lib/ddig/resolver/do53.rb
Overview
DNS Resolver of UDP/53
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#aaaa ⇒ Object
readonly
Returns the value of attribute aaaa.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#nameservers ⇒ Object
readonly
Returns the value of attribute nameservers.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(hostname:, nameservers: nil, ip: nil) ⇒ Do53
constructor
A new instance of Do53.
- #lookup ⇒ Object
- #set_nameservers ⇒ Object
- #to_cli ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(hostname:, nameservers: nil, ip: nil) ⇒ Do53
Returns a new instance of Do53.
11 12 13 14 15 16 17 |
# File 'lib/ddig/resolver/do53.rb', line 11 def initialize(hostname:, nameservers: nil, ip: nil) @hostname = hostname @ip = ip @nameserver = Ddig::Nameserver.new(nameservers: nameservers) set_nameservers end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
9 10 11 |
# File 'lib/ddig/resolver/do53.rb', line 9 def a @a end |
#aaaa ⇒ Object (readonly)
Returns the value of attribute aaaa.
9 10 11 |
# File 'lib/ddig/resolver/do53.rb', line 9 def aaaa @aaaa end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/ddig/resolver/do53.rb', line 8 def hostname @hostname end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
8 9 10 |
# File 'lib/ddig/resolver/do53.rb', line 8 def ip @ip end |
#nameservers ⇒ Object (readonly)
Returns the value of attribute nameservers.
8 9 10 |
# File 'lib/ddig/resolver/do53.rb', line 8 def nameservers @nameservers end |
Instance Method Details
#as_json ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/ddig/resolver/do53.rb', line 37 def as_json(*) { a: @a, aaaa: @aaaa, hostname: @hostname, nameservers: @nameservers, ip: @ip, } end |
#lookup ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ddig/resolver/do53.rb', line 19 def lookup if @nameservers.empty? return nil end @a = Resolv::DNS.open(nameserver: @nameservers) do |dns| ress = dns.getresources(@hostname, Resolv::DNS::Resource::IN::A) ress.map { |resource| resource.address.to_s } end @aaaa = Resolv::DNS.open(nameserver: @nameservers) do |dns| ress = dns.getresources(@hostname, Resolv::DNS::Resource::IN::AAAA) ress.map { |resource| resource.address.to_s } end self end |
#set_nameservers ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ddig/resolver/do53.rb', line 65 def set_nameservers @nameservers = @nameserver.servers if @ip == :ipv4 @nameservers = @nameserver.servers_ipv4 end if @ip == :ipv6 @nameservers = @nameserver.servers_ipv6 end end |
#to_cli ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ddig/resolver/do53.rb', line 51 def to_cli @a.each do |address| rr_type = 'A' puts "#{@hostname}\t#{rr_type}\t#{address}" end @aaaa.each do |address| rr_type = 'AAAA' puts "#{@hostname}\t#{rr_type}\t#{address}" end puts puts "# SERVER: #{@nameservers.join(', ')}" end |
#to_json(*args) ⇒ Object
47 48 49 |
# File 'lib/ddig/resolver/do53.rb', line 47 def to_json(*args) as_json.to_json end |