Git Product home page Git Product logo

dnsruby's People

Contributors

alexdalitz avatar byroot avatar cedespeaux avatar composerinteralia avatar elibus avatar jhawthorn avatar karlerikounapuu avatar keithrbennett avatar kenchan avatar kubicek avatar kyledrake avatar mimuret avatar noraj avatar nsmethwick-fastly avatar nwitkowski avatar otahi avatar parkr avatar pghazanfari avatar rdark avatar rdoherty-fastly avatar rkday avatar seandilda avatar tangofoxtrot avatar tg90nor avatar tucker-altiscale avatar zarqman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dnsruby's Issues

dnsruby freezes (very rarely)

We have had this happen two times in a year, for a task that runs daily, so it is very rare.

We have the following script (I abbreviated it a bit):

resolver = Dnsruby::Resolver.new(nameserver: ["8.8.8.8", "8.8.4.4"])
resolver.retry_times = 3
record_type = "MX"

domains.each do |domain|
  begin
    response = resolver.query(domain, record_type)
    if response.header.ancount == 0
      puts "Missing #{record_type} record for domain \"#{domain}\""
    end
  rescue Dnsruby::NXDomain
    puts "Domain \"#{domain}\" does not exist"
  rescue Dnsruby::ResolvTimeout, Dnsruby::ServFail, Dnsruby::ResolvError, Dnsruby::OtherResolvError
    puts "Error trying to resolve domain \"#{domain}\""
  end
end

The job was killed after 24h, with the following stack trace:

File "/app/vendor/bundle/ruby/2.5.0/gems/dnsruby-1.61.2/lib/dnsruby/resolver.rb", line 253, in pop
File "/app/vendor/bundle/ruby/2.5.0/gems/dnsruby-1.61.2/lib/dnsruby/resolver.rb", line 253, in send_message
File "/app/vendor/bundle/ruby/2.5.0/gems/dnsruby-1.61.2/lib/dnsruby/resolver.rb", line 203, in query

This does not run in a multi-threaded environment, but as a dedicated process which runs this task.

Delete all NAPTR records for a name results in an exception

Take this example intended to delete all NAPTR records with name somename.mysubdomain.example.net:

resolver = Dnsruby::Resolver.new({nameserver: 'mymaster.example.net'})
update = Dnsruby::Update.new('mysubdomain.example.net')
update.delete('somename.mysubdomain.example.net', 'NAPTR')
response = resolver.send_message(update)

The above pattern is shown (but for A records instead of NAPTR) in the comments for update.rb. This results in an exception:

TypeError: no implicit conversion of nil into Integer
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/encoder.rb:19:in `pack'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/encoder.rb:19:in `put_pack'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resource/NAPTR.rb:79:in `encode_rdata'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/encoder.rb:51:in `block in put_rr'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/encoder.rb:29:in `put_length16'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/encoder.rb:51:in `put_rr'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/message.rb:557:in `block (3 levels) in encode'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/message.rb:556:in `each'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/message.rb:556:in `block (2 levels) in encode'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/message.rb:555:in `each'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/message.rb:555:in `block in encode'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/encoder.rb:6:in `initialize'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/message.rb:548:in `new'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/message/message.rb:548:in `encode'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/packet_sender.rb:720:in `make_query_packet'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/packet_sender.rb:334:in `send_async'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resolver.rb:1009:in `block (3 levels) in tick'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resolver.rb:995:in `each'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resolver.rb:995:in `block (2 levels) in tick'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resolver.rb:985:in `each'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resolver.rb:985:in `block in tick'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resolver.rb:983:in `synchronize'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/resolver.rb:983:in `tick'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/select_thread.rb:807:in `block in send_tick_to_observers'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/select_thread.rb:806:in `each'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/select_thread.rb:806:in `send_tick_to_observers'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/select_thread.rb:171:in `do_select'
	from /Users/chrisdonadeo/Repos/Dashboard/.gems/gems/dnsruby-1.60.1/lib/dnsruby/select_thread.rb:153:in `block in check_select_thread_synchronized'

Cannot differentiate between failed DNSSEC and unsigned

The security_level is INSECURE both for DNSSEC failures (bad signature) and when there is no DNSSEC info available. These should be two different levels.

require 'dnsruby'
require 'pp'

rec = Dnsruby::Recursor.new
rec.hints = ["198.41.0.4","192.228.79.201","192.33.4.12","199.7.91.13","192.203.230.10","192.5.5.241","192.112.36.4","128.63.2.53","192.36.148.17","192.58.128.30","193.0.14.129","199.7.83.42","202.12.27.33"]

pp rec.query("www.dnssec-failed.org")
pp rec.query("www.amazon.com")

CDNSKEY CDS and URI records not supported

I just discovered that the following record types are not supported:
CDNSKEY and CDS as defined in RFC7344
URI as defined in RFC7553

Furthermore when reading a TSIG response from a zone file which has been created using dig -y ..., the <keyname>. 0 ANY TSIG hmac-sha256. 1518478325 300 32 <tsig_data> 41534 NOERROR 0 RR emitted by dig causes a parse error.

Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8

[15] pry(main)> require "dnsruby"
=> true

[16] pry(main)> Dnsruby::DNS.new.getaddress("räksmörgås.josefßon.org")
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
from /Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:32:in `put_string'

[17] pry(main)> Error: incompatible character encodings: ASCII-8BIT and UTF-8
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:32:in `put_string'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:72:in `put_label'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:61:in `block in put_labels'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:54:in `each_index'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:54:in `put_labels'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:50:in `put_name'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/message.rb:553:in `block (2 levels) in encode'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/message.rb:552:in `each'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/message.rb:552:in `block in encode'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/encoder.rb:6:in `initialize'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/message.rb:549:in `new'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/message/message.rb:549:in `encode'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/packet_sender.rb:693:in `make_query_packet'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/packet_sender.rb:331:in `send_async'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/resolver.rb:1007:in `block (3 levels) in tick'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/resolver.rb:993:in `each'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/resolver.rb:993:in `block (2 levels) in tick'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/resolver.rb:983:in `each'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/resolver.rb:983:in `block in tick'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/resolver.rb:981:in `synchronize'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/resolver.rb:981:in `tick'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/select_thread.rb:807:in `block in send_tick_to_observers'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/select_thread.rb:806:in `each'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/select_thread.rb:806:in `send_tick_to_observers'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/select_thread.rb:171:in `do_select'
/Users/dentarg/.gem/ruby/2.2.3/gems/dnsruby-1.59.0/lib/dnsruby/select_thread.rb:70:in `block (2 levels) in initialize'

[17] pry(main)> RUBY_DESCRIPTION
=> "ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]"

Also strange: the second exception with the long backtrace pops out some seconds later after I have executed Dnsruby::DNS.new.getaddress("räksmörgås.josefßon.org") and gotten the first exception

`create': cannot interpret as DNS name: nil (ArgumentError)

Hi, I'm trying to update dns server with MX record, am i missing something?

require 'dnsruby'

new_ip     = '172.16.16.1'
domain     = 'vulnerable.zone'
new_domain = 'mx.vulnerable.zone'
dns_server = '172.16.16.134'

res    = Dnsruby::Resolver.new({:nameserver => dns_server})
update = Dnsruby::Update.new(domain)

#=> Add
update.present(domain)
update.add(dns_server, Dnsruby::Types.MX, 10, new_domain)

begin
  reply = res.send_message(update)
  puts "Update succeeded"
rescue Exception => e
  p "Update failed: #{e.backtrace}"
end

Getting an error

/var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/name.rb:60:in `create': cannot interpret as DNS name: nil (ArgumentError)
        from /var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resource/MX.rb:42:in `from_string'
        from /var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resource/RR.rb:113:in `initialize'
        from /var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resource/RR.rb:282:in `new'
        from /var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resource/RR.rb:282:in `_get_subclass'
        from /var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resource/RR.rb:245:in `new_from_string'
        from /var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/resource/RR.rb:402:in `create'
        from /var/lib/gems/2.3.0/gems/dnsruby-1.60.0/lib/dnsruby/update.rb:238:in `add'
        from dns_mx_update.rb:18:in `<main>'

The Additional section of Dnsruby::Message sometimes returns false when compared to itself.

The Additional section of Dnsruby::Message sometimes returns false when compared to itself, i.e.

(a_message.additional == a_message.additional) => false

This results in the entire message when compared to itself returning false:

(a_message == a_message) => false

I think it has something to do with the contained RRSet's and/or RR's; the act of comparing them may return new objects who don't have an == method defined, resulting in == returning false for different instances even though they are semantically equal.

A script illustrating this is at https://gist.github.com/keithrbennett/469afd51f7fd075fdc5a , and also pasted here:

#!/usr/bin/env ruby

# keithrbennett, 2015-01-06
#
# Illustrates that the Additional section of Dnsruby::Message
# sometimes returns false when compared to itself, i.e.
# (a_message.additional == a_message.additional) => false
#
# which results in the entire message when compared to itself returning false:
# (a_message == a_message) => false

# I think it has something to do with the contained RRSet's and/or RR's;
# the act of comparing them may return new objects who don't have an ==
# method defined, resulting in == returning false for different instances
# even though they are semantically equal.

require 'dnsruby'
include Dnsruby

def response_from_network
  query = Message.new('cnn.com', 'NS')
  Resolver.new.send_message(query)
end

def response_saved
  response_as_string = "\x10\a\x81\x90\x00\x01\x00\x04\x00\x00\x00\x06\x03cnn\x03com\x00\x00\x02\x00\x01\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x14\x03ns3\ntimewarner\x03net\x00\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x11\x03ns2\x03p42\x06dynect\xC04\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x06\x03ns1\xC0)\xC0\f\x00\x02\x00\x01\x00\x01QC\x00\x06\x03ns1\xC0I\xC0%\x00\x01\x00\x01\x00\x001\xA2\x00\x04\xC7\aD\xEE\xC0E\x00\x01\x00\x01\x00\x00\xB1\x0E\x00\x04\xCC\r\xFA*\xC0b\x00\x01\x00\x01\x00\x009`\x00\x04\xCCJl\xEE\xC0t\x00\x01\x00\x01\x00\x00\xBDg\x00\x04\xD0NF*\xC0t\x00\x1C\x00\x01\x00\x00\x00\xBB\x00\x10 \x01\x05\x00\x00\x90\x00\x01\x00\x00\x00\x00\x00\x00\x00B\x00\x00)\x0F\xA0\x00\x00\x80\x00\x00\x00".force_encoding("ASCII-8BIT")
  Message.decode(response_as_string)
end

def report_header
  "%7s  %s\n#{'-' * 40}" % %w(T/F  Object)
end

def report(term, object)
  puts("%7s  %s" % [object == object, term])
end


r = response_saved

# Uncomment this if you want to test a real network call:
# r = response_from_network

puts report_header
report('response', r)
report('response.header', r.header)
report('response.question', r.question)
report('response.answer', r.answer)
report('response.additional', r.additional)

=begin

Outputs:

   T/F  Object
----------------------------------------
  false  response
   true  response.header
   true  response.question
   true  response.answer
  false  response.additional

=end

fatal: No live threads left: Deadlock? when "IDN support" exception is raised

I have had problems with dnsruby "crashing" when it encounters a string which should have been punycoded. See the following example session:

irb(main):002:0> require "dnsruby"
=> true
irb(main):003:0> resolver = Dnsruby::Resolver.new(nameserver: ["8.8.8.8", "8.8.4.4"])
=> #<Dnsruby::Resolver:0x00007fa4c5b89cc0 @resolver_ruby=nil, @src_address=nil, @src_address6=nil, @single_res_mutex=#<Thread::Mutex:0x00007fa4c5b89c48>, @configured=true, @do_caching=true, @config=Config - nameservers : 8.8.8.8, 8.8.4.4,  domain : [#<Dnsruby::Name::Label unix>, #<Dnsruby::Name::Label net>], search : local,  ndots : 1, @do_validation=false, @query_timeout=0, @retry_delay=5, @retry_times=1, @packet_timeout=5, @port=53, @udp_size=4096, @dnssec=false, @use_tcp=false, @no_tcp=false, @tcp_pipelining=false, @tcp_pipelining_max_queries=5, @tsig=nil, @ignore_truncation=false, @src_port=[0], @recurse=true, @single_resolvers=[#<Dnsruby::PacketSender:0x00007fa4c5b80ff8 @ipv6=false, @packet_timeout=5, @port=53, @udp_size=4096, @dnssec=false, @use_tcp=false, @no_tcp=false, @tsig=nil, @ignore_truncation=false, @src_address="0.0.0.0", @src_address6="::", @src_port=[0], @recurse=true, @tcp_pipelining=false, @tcp_pipelining_max_queries=5, @use_counts={}, @server="8.8.8.8">, #<Dnsruby::PacketSender:0x00007fa4c5b7b288 @ipv6=false, @packet_timeout=5, @port=53, @udp_size=4096, @dnssec=false, @use_tcp=false, @no_tcp=false, @tsig=nil, @ignore_truncation=false, @src_address="0.0.0.0", @src_address6="::", @src_port=[0], @recurse=true, @tcp_pipelining=false, @tcp_pipelining_max_queries=5, @use_counts={}, @server="8.8.4.4">]>
irb(main):004:0> resolver.query("google.com", "MX")
=> #<Dnsruby::Message:0x00007fa4c5068f80 @header=#<Dnsruby::Header:0x00007fa4c5b73c68 @id=75, @qr=true, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=true, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=5, @arcount=0>, @question=[#<Dnsruby::Question:0x00007fa4c5b73380 @qtype=MX, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[#<Dnsruby::RR::IN::MX:0x00007fa4c5b71c10 @rdata=[40, #<Dnsruby::Name: alt3.aspmx.l.google.com.>], @preference=40, @exchange=#<Dnsruby::Name: alt3.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=599, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5b703d8 @rdata=[30, #<Dnsruby::Name: alt2.aspmx.l.google.com.>], @preference=30, @exchange=#<Dnsruby::Name: alt2.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=599, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5b69858 @rdata=[50, #<Dnsruby::Name: alt4.aspmx.l.google.com.>], @preference=50, @exchange=#<Dnsruby::Name: alt4.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=599, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5b631b0 @rdata=[10, #<Dnsruby::Name: aspmx.l.google.com.>], @preference=10, @exchange=#<Dnsruby::Name: aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=599, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5b60c80 @rdata=[20, #<Dnsruby::Name: alt1.aspmx.l.google.com.>], @preference=20, @exchange=#<Dnsruby::Name: alt1.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=599, @type=MX, @klass=IN>], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom="8.8.8.8", @answerip="8.8.8.8", @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false, @answersize=136>
irb(main):005:0> resolver.query("google.com", "MX")
=> #<Dnsruby::Message:0x00007fa4c4b04a80 @header=#<Dnsruby::Header:0x00007fa4c4b045a8 @id=46884, @qr=true, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=true, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=5, @arcount=0>, @question=[#<Dnsruby::Question:0x00007fa4c4affd28 @qtype=MX, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[#<Dnsruby::RR::IN::MX:0x00007fa4c4afe388 @rdata=[40, #<Dnsruby::Name: alt3.aspmx.l.google.com.>], @preference=40, @exchange=#<Dnsruby::Name: alt3.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=597, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5b03f08 @rdata=[30, #<Dnsruby::Name: alt2.aspmx.l.google.com.>], @preference=30, @exchange=#<Dnsruby::Name: alt2.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=597, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5b02608 @rdata=[50, #<Dnsruby::Name: alt4.aspmx.l.google.com.>], @preference=50, @exchange=#<Dnsruby::Name: alt4.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=597, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5b00f38 @rdata=[10, #<Dnsruby::Name: aspmx.l.google.com.>], @preference=10, @exchange=#<Dnsruby::Name: aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=597, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5afb858 @rdata=[20, #<Dnsruby::Name: alt1.aspmx.l.google.com.>], @preference=20, @exchange=#<Dnsruby::Name: alt1.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=597, @type=MX, @klass=IN>], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=true>
irb(main):006:0> resolver.query("googlöe.com", "MX")
Dnsruby::OtherResolvError: IDN support currently requires punycode string
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:39:in `rescue in put_string'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:34:in `put_string'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:80:in `put_label'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:69:in `block in put_labels'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:62:in `each_index'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:62:in `put_labels'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:58:in `put_name'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/message.rb:552:in `block (2 levels) in encode'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/message.rb:551:in `each'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/message.rb:551:in `block in encode'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/encoder.rb:6:in `initialize'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/message.rb:548:in `new'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/message/message.rb:548:in `encode'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/packet_sender.rb:720:in `make_query_packet'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/packet_sender.rb:334:in `send_async'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:1010:in `block (3 levels) in tick'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:996:in `each'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:996:in `block (2 levels) in tick'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:986:in `each'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:986:in `block in tick'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:984:in `synchronize'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:984:in `tick'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:919:in `send_async'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:401:in `send_async'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:251:in `send_message'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:203:in `query'
	from (irb):6
	from /Users/fabian/.rbenv/versions/2.3.7/bin/irb:11:in `<main>'
irb(main):007:0> resolver.query("google.com", "MX")
=> #<Dnsruby::Message:0x00007fa4c5ac9808 @header=#<Dnsruby::Header:0x00007fa4c5ac9060 @id=3876, @qr=true, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=true, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=5, @arcount=0>, @question=[#<Dnsruby::Question:0x00007fa4c5ac84f8 @qtype=MX, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[#<Dnsruby::RR::IN::MX:0x00007fa4c5ac2c60 @rdata=[40, #<Dnsruby::Name: alt3.aspmx.l.google.com.>], @preference=40, @exchange=#<Dnsruby::Name: alt3.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=592, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5ac1450 @rdata=[30, #<Dnsruby::Name: alt2.aspmx.l.google.com.>], @preference=30, @exchange=#<Dnsruby::Name: alt2.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=592, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c4a8fd48 @rdata=[50, #<Dnsruby::Name: alt4.aspmx.l.google.com.>], @preference=50, @exchange=#<Dnsruby::Name: alt4.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=592, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c4a8e678 @rdata=[10, #<Dnsruby::Name: aspmx.l.google.com.>], @preference=10, @exchange=#<Dnsruby::Name: aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=592, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c4a8ce68 @rdata=[20, #<Dnsruby::Name: alt1.aspmx.l.google.com.>], @preference=20, @exchange=#<Dnsruby::Name: alt1.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=592, @type=MX, @klass=IN>], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=true>
irb(main):008:0> resolver.query("google.com", "MX")
=> #<Dnsruby::Message:0x00007fa4c5a70cd0 @header=#<Dnsruby::Header:0x00007fa4c5a707f8 @id=53363, @qr=true, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=true, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=0, @ancount=5, @arcount=0>, @question=[#<Dnsruby::Question:0x00007fa4c5a71040 @qtype=MX, @qclass=IN, @qname=#<Dnsruby::Name: google.com.>>], @answer=[#<Dnsruby::RR::IN::MX:0x00007fa4c5a6aab0 @rdata=[40, #<Dnsruby::Name: alt3.aspmx.l.google.com.>], @preference=40, @exchange=#<Dnsruby::Name: alt3.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=591, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5a69228 @rdata=[30, #<Dnsruby::Name: alt2.aspmx.l.google.com.>], @preference=30, @exchange=#<Dnsruby::Name: alt2.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=591, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5a63ad0 @rdata=[50, #<Dnsruby::Name: alt4.aspmx.l.google.com.>], @preference=50, @exchange=#<Dnsruby::Name: alt4.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=591, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5a624a0 @rdata=[10, #<Dnsruby::Name: aspmx.l.google.com.>], @preference=10, @exchange=#<Dnsruby::Name: aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=591, @type=MX, @klass=IN>, #<Dnsruby::RR::IN::MX:0x00007fa4c5a60bc8 @rdata=[20, #<Dnsruby::Name: alt1.aspmx.l.google.com.>], @preference=20, @exchange=#<Dnsruby::Name: alt1.aspmx.l.google.com.>, @name=#<Dnsruby::Name: google.com.>, @ttl=591, @type=MX, @klass=IN>], @authority=[], @additional=[], @tsigstate=:Unsigned, @signing=false, @tsigkey=nil, @answerfrom=nil, @answerip=nil, @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=true>
irb(main):009:0> resolver.query("googlöe.com", "MX")
Dnsruby::ResolvTimeout: Query timed out
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:257:in `send_message'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:203:in `query'
	from (irb):9
	from /Users/fabian/.rbenv/versions/2.3.7/bin/irb:11:in `<main>'
irb(main):010:0> resolver.query("googlöe.com", "MX")
fatal: No live threads left. Deadlock?
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:253:in `pop'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:253:in `send_message'
	from /Users/fabian/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/dnsruby-1.60.2/lib/dnsruby/resolver.rb:203:in `query'
	from (irb):10
	from /Users/fabian/.rbenv/versions/2.3.7/bin/irb:11:in `<main>'

I have a suspicion that this happens because the error is just raised inside the thread, while other exception are gracefully pushed to the queue. This is just hunch however, I've only read the code very superficially.

Versioning issue

Props to @mlocher at Codeship for working this out!

$ gem install dnsruby
Fetching: dnsruby-1.59.2.gem (100%)
Installing dnsruby...
  For issues and source code: https://github.com/alexdalitz/dnsruby
  For general discussion (please tell us how you use dnsruby): https://groups.google.com/forum/#!forum/dnsruby
Successfully installed dnsruby-1.59.2
1 gem installed

even though https://rubygems.org/gems/dnsruby shows that 1.59.3 is available since May 25.

When I try to install that version explicitly I get an error message

$ gem install dnsruby -v 1.59.3
ERROR:  Could not find a valid gem 'dnsruby' (= 1.59.3) in any repository
ERROR:  Possible alternatives: Dnsruby

JRuby 9000: deprecation warning "... interpreted as binary operator"

Thank you for your gem.

We are getting this deprecation warning with JRuby 9.1.12:

.rbenv/versions/jruby-9.1.12.0/lib/ruby/gems/shared/gems/dnsruby-1.60.2/lib/dnsruby/message/header.rb:215: warning: `+' after local variable or literal is interpreted as binary operator

It's not urgent, or important, but it is noisy in our logs. I didn't find any reference to this, so I thought I would file it.

Thanks again, your gem is useful for us!
KT

bogus invalid key issue (patch included)

ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

The .e and .n fields/methods do not exist anymore in OpenSSL::PKey::RSA

This triggers a bogus invalid key error when the code is used (hiding the true Exception about the
method not being found)
This tiny patch calls the setter.

Changes to be committed:
    modified:   lib/dnsruby/resource/DNSKEY.rb

openssl::PKey::RSA.patch.zip

Timeout error deprecated.

Running this on Ruby 2.3.0, I'm getting "warning: constant Dnsruby::TimeoutError is deprecated"

It appears TimeoutError has been deprecated from Ruby as off 2.3.0 in favor of Timeout::Error. I changed my local Dnsruby gem to class ResolvTimeout < Timeout::Error, and that removed the deprecation warning in my dev env, but I'm not sure at this point what other ramifications there may be. (hopefully none).

Documentation does not show how to update a PTR record

I would like to update a PTR record with dnsruby. The documentation does not include any examples or reference to updating a PTR record. I'd like to do the following . . .

update.add('foo.example.com.', 'A', 86400, '192.168.1.2')
update.add('2.1.168.192.in-addr.arpa.', 'PTR', 86400, 'foo.example.com.')

What is the correct way to do this?

Memleack

Just run this code and get memleak: http://pastebin.com/grCKZqBN
dnsruby produces a lot of strange classes for every request and theese classes are unfree in ruby, because you can't free class definition

prereq on absent(name, 'CNAME') doesn't work with update

When doing an update, if I set a .absent(name, 'CNAME'), then I get an error back. The initial error is a tsignotsigned error. If I switch to using #query_raw, then I see the error is a formerror. If I try an A record or TXT record, there's no error.

This is against bind 9.9.2

Recursor.@@nameservers gets set to bogus array

When doing validation from the root, I see errors like:
Argument nameserver not valid : invalid nameserver config: [#<Dnsruby::Recursor::AddressCache:0x000000071800e0 @hash={"199.7.91.13"=....

I have traced this to an initialization in recursor.rb, where it does:
@resolver = Resolver.new({:nameserver => @@nameservers})
where @@nameservers is just not a list of name servers.
This occurs from Recursor.set_hints, which gets called from query() at: dnsruby/lib/dnsruby/recursor.rb:397.

(rdb:1) p hints
{"d.root-servers.net"=>#<Dnsruby::Recursor::AddressCache:0x00000005c995f0 @hash={"199.7.91.13"=>2015-05-08 17:30:54 -0400, "2001:500:2D::D"=>

The problem appears to be that the hints being collected are an AddressCache, which makes sense to me, but set_hints() doesn't know how to deal with this to make the @@nameservers.
The question is: should set_hints() cope (producing a sane array of strings), or should the initializer to in Resolver accept that it might get a hash of values that area address cache?

Resolver#query returns wrong answer types

Trying to get TXT records for a subdomain but getting a CNAME record instead. Am I missing something here?

>> Dnsruby::Resolver.new.query("domain.com", Dnsruby::Types.TXT).answer.map(&:type)
=> [CNAME, TXT]

ArgumentError (invalid port config: nil) on Dns.new() with no network connection

Calling Dnsruby::DNS.new without a network connection raises and error:

2.5.5 :002 > require "dnsruby"
 => true 
2.5.5 :003 > Dnsruby::VERSION
 => "1.61.2" 
2.5.5 :004 > Dnsruby::DNS.new
Traceback (most recent call last):
        9: from /Users/loaner/.rvm/rubies/ruby-2.5.5/bin/irb:11:in `<main>'
        8: from (irb):4
        7: from (irb):4:in `new'
        6: from /Users/loaner/.rvm/gems/ruby-2.5.5@manager-ruby255/gems/dnsruby-1.61.2/lib/dnsruby/DNS.rb:121:in `initialize'
        5: from /Users/loaner/.rvm/gems/ruby-2.5.5@manager-ruby255/gems/dnsruby-1.61.2/lib/dnsruby/config.rb:80:in `set_config_info'
        4: from /Users/loaner/.rvm/gems/ruby-2.5.5@manager-ruby255/gems/dnsruby-1.61.2/lib/dnsruby/config.rb:97:in `parse_config'
        3: from /Users/loaner/.rvm/gems/ruby-2.5.5@manager-ruby255/gems/dnsruby-1.61.2/lib/dnsruby/config.rb:97:in `synchronize'
        2: from /Users/loaner/.rvm/gems/ruby-2.5.5@manager-ruby255/gems/dnsruby-1.61.2/lib/dnsruby/config.rb:137:in `block in parse_config'
        1: from /Users/loaner/.rvm/gems/ruby-2.5.5@manager-ruby255/gems/dnsruby-1.61.2/lib/dnsruby/config.rb:170:in `port='
ArgumentError (invalid port config: nil)

This used to work in 1.60.2 -- obviously in production the lack of a network connection causes other problems, but we want/expect our rspecs to run without network or reliance on the DNS config of the worker (CI) machine.

It looks like this was introduced when this was added:

Be able to supply port to Dnsruby::DNS
#100 opened on Feb 4, 2016 by dentarg • updated on Jul 4, 2018

This would fix it:

- send("port=", p)
+ send("port=", p || @port)

Recursor vs. Resolver

This is probably not the right place to ask this but I cannot find a mailing list, so either please answer or refer me. Also I am just now learning about the DNS internals, so the question is likely very Newbie!!!

My question is simple: What exactly is the difference between Resolver#query and Recursor#query? It seems to be that Resolver is also recursing.

Header RD flag is overwritten.

If message.header.rd is set to false, when the message is sent, the flag is overwritten to true (see test method test_rd_not_overwritten in tc_resolver.rb). The code at my branch at https://github.com/keithrbennett/dnsruby/tree/fix-rd-overwriting illustrates this (1). If you run:

bundle exec ruby test/tc_resolver.rb --name test_rd_not_overwritten

...you'll see an exception raised that indicates that line 605 in PacketSender is where the value is being overwritten. I would think that sending a message should not result in any change to the original message at all -- is this wrong? If not, why is this being overwritten?

Thanks....

(1) To get a copy of this branch, do this:

git clone [email protected]:keithrbennett/dnsruby.git keith-dnsruby
cd keith-dnsruby
git checkout -b fix-rd-overwriting
git pull origin fix-rd-overwriting

Test failed at tc_resolv

Test failed when running "$ rake test"

TestResolv#test_resolv_address_to_name [/home/user/projects/dnsruby/test/tc_resolv.rb:65]:
--- expected
+++ actual
@@ -1 +1 @@
-"google-public-dns-a.google.com"
+"google-public-dns-a.google.com."

For ruby built-in resolv,

1.9.3-p551 :007 > Resolv.getname("8.8.8.8")
 => "google-public-dns-a.google.com" 

Is this a logic fault or test issue?

  • Tested on ruby 2.3.3 and ruby 1.9.3

resolve lots of dependent records in parallel.

I have about 100K names I need to resolve on a regular basis.

I have used your example mresolve to resolve the names which
works great. But I'd like to get more data for each name,
for instance, would like:

  • A record (with is_cname? flagged)
    • PTR records for each IP returned.
  • NS records
    • A records for each NS
      • PTR record for each A above.
  • MX records
    • A record for each exchange above
      • PTR record for each A record above.
  • TXT records.

Trying to figure out the best way to do this
efficiently, i.e. run async when dependent records
are retrieved and maintain a Queue of $x domains
being processed

Has anyone implemented such a thing?
Also, is it best to use Recursor or Resolver for such a thing?

dnsruby queries localhost when invalid name server specified

First of all, thank you for creating dnsruby! I've using it for monitoring DNS records, and have been really happy with its flexibility.

If I query a name server by hostname, and that hostname cannot be resolved, then dnsruby tries to query localhost instead.

Here are the steps to reproduce:

require 'dnsruby'
resolver = Dnsruby::Resolver.new
resolver.do_caching = false
resolver.dnssec = false
resolver.config.nameserver = ['no-such-nameserver.example.com']
resolver.query('example.com', 'a')

This means that if I try to query an invalid name server from a host which is not running a resolver on localhost, I get this error message:

Dnsruby::OtherResolvError: recvfrom failed from ; Connection refused - recvfrom(2)

If I do the same thing from a system which is running a resolver on localhost, then dnsruby queries it, and returns its results:

=> #<Dnsruby::Message:0x007f81781d0cd0 @Header=#<Dnsruby::Header:0x007f81781d06e0 @id=59590, @qr=true, @opcode=Query, @aa=false, @ad=false, @tc=false, @rd=true, @ra=true, @cd=false, @rcode=NOERROR, @qdcount=1, @nscount=2, @ancount=1, @arcount=4>, @question=[#<Dnsruby::Question:0x007f81781cfba0 @Qtype=A, @qclass=IN, @Qname=#<Dnsruby::Name: example.com.>>], @answer=[#<Dnsruby::RR::IN::A:0x007f81781cf010 @rdata=#<Dnsruby::IPv4 93.184.216.34>, @address=#<Dnsruby::IPv4 93.184.216.34>, @name=#<Dnsruby::Name: example.com.>, @Ttl=60, @type=A, @klass=IN>], @authority=[#<Dnsruby::RR::IN::NS:0x007f81781cdcd8 @rdata=#<Dnsruby::Name: b.iana-servers.net.>, @domainname=#<Dnsruby::Name: b.iana-servers.net.>, @name=#<Dnsruby::Name: example.com.>, @Ttl=57, @type=NS, @klass=IN>, #<Dnsruby::RR::IN::NS:0x007f81781cc6a8 @rdata=#<Dnsruby::Name: a.iana-servers.net.>, @domainname=#<Dnsruby::Name: a.iana-servers.net.>, @name=#<Dnsruby::Name: example.com.>, @Ttl=57, @type=NS, @klass=IN>], @Additional=[#<Dnsruby::RR::IN::A:0x007f81781cb500 @rdata=#<Dnsruby::IPv4 199.43.132.53>, @address=#<Dnsruby::IPv4 199.43.132.53>, @name=#<Dnsruby::Name: a.iana-servers.net.>, @Ttl=57, @type=A, @klass=IN>, #<Dnsruby::RR::IN::AAAA:0x007f81781ca3d0 @rdata=#<Dnsruby::IPv6 2001:500:8C::53>, @address=#<Dnsruby::IPv6 2001:500:8C::53>, @name=#<Dnsruby::Name: a.iana-servers.net.>, @Ttl=57, @type=AAAA, @klass=IN>, #<Dnsruby::RR::IN::A:0x007f81781c94d0 @rdata=#<Dnsruby::IPv4 199.43.133.53>, @address=#<Dnsruby::IPv4 199.43.133.53>, @name=#<Dnsruby::Name: b.iana-servers.net.>, @Ttl=57, @type=A, @klass=IN>, #<Dnsruby::RR::IN::AAAA:0x007f81781c85d0 @rdata=#<Dnsruby::IPv6 2001:500:8D::53>, @address=#<Dnsruby::IPv6 2001:500:8D::53>, @name=#<Dnsruby::Name: b.iana-servers.net.>, @Ttl=57, @type=AAAA, @klass=IN>], @tsigstate=:Unsigned, @Signing=false, @tsigkey=nil, @answerfrom="127.0.0.1", @answerip="127.0.0.1", @send_raw=false, @do_validation=true, @do_caching=true, @security_level=UNCHECKED, @security_error=nil, @cached=false, @answersize=181>

My expectation is that if an invalid name server is specified, dnsruby will return an error message, indicating that.

Is this an issue with dnsruby, or am I using it incorrectly?

Thanks,

Matt

Dnsruby::DecodeError on ANY query.

Am I doing ANY query wrong?

require "dnsruby"
include Dnsruby
@resolver = Dnsruby::Resolver.new({:nameserver => "8.8.8.8"})
m = Message.new("google.com", Types.ANY)
pp @resolver.send_message(m)

results in:
./t1.rb
/home/joe/projects/rubydns-getter/vendor/ruby/2.1.0/gems/dnsruby-1.60.1/lib/dnsruby/message/decoder.rb:32:in `assert_buffer_position_valid': requested position of 258 must be between 0 and buffer size (165). (Dnsruby::DecodeError)

Just noticed that: m = Message.new("yahoo.com", Types.ANY) works. so something about querying info about google.com.

DNSSEC not working

It seems DNSSEC checking is not working. Using the example digroot.rb script, the answer is always coming back with @security_level=INSECURE, regardless of the name being looked up.

Example:
ruby digroot.rb www.pir.org.

Is is expected that this should show something other than INSECURE?

TypeError: no implicit conversion of nil into Array on Dnsruby::DNS#each_resource

I've got TypeError when call Dnsruby::DNS#each_resource
for example when i try:

res = Dnsruby::DNS.new
res.each_resource('gmail.com','MX'){|rr| puts rr}

i've got

TypeError: no implicit conversion of nil into Array
	from /usr/local/bundle/gems/dnsruby-1.60.2/lib/dnsruby/config.rb:437:in `+'
	from /usr/local/bundle/gems/dnsruby-1.60.2/lib/dnsruby/config.rb:437:in `generate_candidates'
	from /usr/local/bundle/gems/dnsruby-1.60.2/lib/dnsruby/DNS.rb:281:in `send_query'
	from /usr/local/bundle/gems/dnsruby-1.60.2/lib/dnsruby/DNS.rb:231:in `each_resource'
	from (irb):42

it running from kubernetes container.
res.config is

Config - nameservers : 10.96.0.10,  domain : empty, search : default.svc.cluster.local, svc.cluster.local, cluster.local,  ndots : 5

but when i run this code from local machine it works fine.

Be able to supply port to Dnsruby::DNS

With resolv I can do this:

Resolv::DNS.new(nameserver_port: [["8.8.8.8", 53], ["8.8.4.4", 53]])

With dnsruby I can do this

Dnsruby::Resolver.new(nameserver: ["8.8.8.8", "8.8.4.4"], port: 53)

but Dnsruby::Resolver is much more low-level than what I want. I want to use Dnsruby::DNS which has all the nice methods like getaddress and getname.

The use-case I have for this is that, in my integration test, I actually start NSD on a custom port and make real queries. So my tests passes that port on to my dns client class in the application, in the test setup. In production I default to the standard port.

What do you think about this?

Is it an relatively easy change so I could try make a pull request for it?

dnsruby 1.60.1 breaks https://github.com/opendnssec/dnssec-monitor

Here is a Dockerfile which shows how dnsruby 1.60.1 breaks https://github.com/opendnssec/dnssec-monitor
dnsruby Versions which work are 1.58, 1.59, 1.60.0

cat <<EOF >Dockerfile
FROM debian:stretch-slim

RUN apt-get update
&& apt-get install -y --no-install-recommends
ruby
gem
wget
unzip
dnsutils
vim-tiny
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*

RUN gem install -r dnsruby -v 1.58 && gem install -r soap2r
RUN wget https://github.com/opendnssec/dnssec-monitor/archive/master.zip
RUN unzip master.zip

WORKDIR /dnssec-monitor-master/lib/
RUN dig . dnskey > root.key

CMD ./nagios_dnssec.rb -z at --rootkey root.key -n j.ns.at -v
EOF

build docker container:
docker build -t "nagios-dnssec:stretch" .

run bash within the container:
docker run -it nagios-dnssec:stretch bash

run command with working version 1.58 within the container:
./nagios_dnssec.rb -z at --rootkey root.key -n j.ns.at -v

install newer dnsruby version within the container:
gem install -r dnsruby -v 1.60.1

run command with broken version 1.60.1 within the container:
./nagios_dnssec.rb -z at --rootkey root.key -n j.ns.at -v

dnsruby can't connect to 192.168.0.1:53 from 0.0.0.0:64859

I'm trying to do a basic MX record check with:

    res = Dnsruby::Resolver.new
    ret = res.query(domain, Types.TXT)
    ret.answer

and getting the following response all too often:

<IOError: dnsruby can't connect to 192.168.0.1:53 from 0.0.0.0:64859, use_tcp=true, exception = Errno::ECONNREFUSED, Connection refused - connect(2) for "192.168.0.1" port 53

How can I avoid this error? When I past the domain being checked into online mx checker tools it shows me the MX records.

Unit tests sometimes fail with TCP Pipelining timing error.

Travis CI reports the following error when testing with Ruby head:

  1) Failure:

TestTCPPipelining#test_TCP_pipelining_socket_eof [/home/travis/build/alexdalitz/dnsruby/test/tc_tcp_pipelining.rb:190]:

Expected #<Dnsruby::SocketEofResolvError: TCP socket closed before all answers received> to be nil.

  2) Failure:

TestTCPPipelining#test_TCP_pipelining_timeout [/home/travis/build/alexdalitz/dnsruby/test/tc_tcp_pipelining.rb:115]:

Expected #<Dnsruby::SocketEofResolvError: TCP socket closed before all answers received> to be nil.

  3) Failure:

TestTCPPipelining#test_TCP_pipelining_timeout_in_send [/home/travis/build/alexdalitz/dnsruby/test/tc_tcp_pipelining.rb:115]:

Expected #<Dnsruby::SocketEofResolvError: TCP socket closed before all answers received> to be nil.

These errors do not appear to be related to recent code changes. I noticed that some of the calls to send_async_messages do not override the default wait time of zero seconds. Could that be the problem?

Timeouts During Zone Transfer?

While the Resolver class allows setting timeouts, I could not find anything in the ZoneTransfer class that allows setting my own Resolver or directly setting timeouts. In my testing, if the DNS server cannot be connected to, then Errno::ETIMEDOUT will be thrown after some amount of time, but it's not adjustable. I think it might be possible to hang entirely if connection succeeds but some sort of network issue prevents progress from being made, as I've had some background workers lock up in ZoneTransfer#transfer.

Cannot set validation policy

Dnsruby::Dnssec.validation_policy = Dnsruby::Dnssec::ValidationPolicy::ALWAYS_ROOT_ONLY

The above line causes a traceback because

if ((p >= ALWAYS_ROOT_ONY) && (p <= ALWAYS_LOCAL_ANCHORS))
has three issues:

  • ALWAYS_ROOT_ONY should be ALWAYS_ROOT_ONLY
  • ALWAYS_LOCAL_ANCHORS should be ALWAYS_LOCAL_ANCHORS_ONLY
  • Both need to be prefixed with ValidationPolicy::

Move includes inside classes.

There are many include Dnsruby statements outside of class definitons. include is generally intended to be used inside class definitions, and I think that was the intent. It would be helpful to move them inside class definitions.

Dnsruby 1.60.1 gem missing dependency.

The gem spec seems to be missing the addressable dependency, so it fails to load with require. I see addressable in the Gemfile, but it's not in the .gemspec.

Here's a test with irb:

$ irb
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'dnsruby'
LoadError: cannot load such file -- addressable
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Library/Ruby/Gems/2.3.0/gems/dnsruby-1.61.0/lib/dnsruby/name.rb:30:in `<module:Dnsruby>'
	from /Library/Ruby/Gems/2.3.0/gems/dnsruby-1.61.0/lib/dnsruby/name.rb:16:in `<top (required)>'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Library/Ruby/Gems/2.3.0/gems/dnsruby-1.61.0/lib/dnsruby/message/message.rb:17:in `<top (required)>'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Library/Ruby/Gems/2.3.0/gems/dnsruby-1.61.0/lib/dnsruby.rb:17:in `<top (required)>'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
	from (irb):2
	from /usr/bin/irb:11:in `<main>'

Here's the dependency list from the GEM I downloaded. It has everything but addressable:

--- !ruby/object:Gem::Specification
name: dnsruby
version: !ruby/object:Gem::Version
  version: 1.61.0
platform: ruby
authors:
- Alex Dalitz
autorequire: 
bindir: bin
cert_chain: []
date: 2018-07-11 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
  name: pry
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '0.10'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '0.10'
- !ruby/object:Gem::Dependency
  name: pry-byebug
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '2.0'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '2.0'
- !ruby/object:Gem::Dependency
  name: rake
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: 10.3.2
    - - "~>"
      - !ruby/object:Gem::Version
        version: '10'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: 10.3.2
    - - "~>"
      - !ruby/object:Gem::Version
        version: '10'
- !ruby/object:Gem::Dependency
  name: minitest
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '5.4'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '5.4'
- !ruby/object:Gem::Dependency
  name: rubydns
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '1.0'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '1.0'
- !ruby/object:Gem::Dependency
  name: nio4r
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '1.1'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '1.1'
- !ruby/object:Gem::Dependency
  name: minitest-display
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: 0.3.0
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: 0.3.0
- !ruby/object:Gem::Dependency
  name: coveralls
  requirement: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '0.7'
  type: :development
  prerelease: false
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - "~>"
      - !ruby/object:Gem::Version
        version: '0.7'

Can't delete record while specifying rdata

If you specify rdata in an update request, the formatted packet does not include the specified rdata.

It looks like this may be caused by the fix for #102, since delete requests and must be absent prereqs both have a class of NONE

RubyDNS 2.0.0 available

This update is a big improvement to stability, if you have time to try it out and report any issues that would be great.

It would help resolve the usage of celluloid in your testing, as celluloid is no longer used and there is no longer any globally visible system that needs to be "booted".

Dnsruby::DNS always throws Dnsruby::NXDomain when search is in /etc/resolv.conf

Scenario:

In /etc/resolv.conf:

nameserver 100.64.0.10
search test.svc.cluster.local svc.cluster.local cluster.local us-west-1.compute.internal
options ndots:5

When doing Dnsruby::DNS.new.send_query('uue.org'), dnsruby will lookup uue.org.test.svc.cluster.local., uue.org.svc.cluster.local., uue.org.svc.cluster.local., uue.org.cluster.local. and uue.org.us-west-1.compute.internal., but NOT uue.org..

This works contrary to any other tools out there. The 'blank' domain without the search list applied should also be looked up so dnsruby behaves like any other tool doing DNS lookups, like ping uue.org just resolves fine for instance.

rubydns no longer works in pipelining tests

A while ago, @nwitkowski added some test code for TCP pipelinining, based on @ioquatix rubydns library. Sadly, the interfaces changed, and the code (plus subsequent changes) no longer works in the tests.
I've spent some time looking at this, and can't get the breaking changes fixed. As a result, I've removed the tests that use rubydnsm, in this commit : 06a23f9

If anybody is able to contribute patches which fix the broken API changes, so I can reinstate this test, I'd be very grateful.

Thanks!

rescue in get_label': Label too long (74, max length=63)

First, Thanks for making Dnsruby that much mature and awesome

I'm trying to PTR 207. 46.197.32 address which is originally the owa.zonetransfer.me IP.

when I do the following

resolver = Dnsruby::Resolver.new
query     = resolver.query('207.46.197.32', 'PTR', 'IN')

It trigers the following error

Dnsruby::DecodeError: Label too long (115, max length=100). Label = anslimite��
                                                                               �everyonegetsit��
responsepoint�  �                                                                               �
                 �xn--frdermittel-ratgeber-39bƕ�
from /var/lib/gems/2.3.0/gems/dnsruby-1.59.3/lib/dnsruby/message/decoder.rb:149:in `rescue in get_label'

However, using host command

host -t ptr 207.46.197.32

It returns all the PTRs which are 1042 ptr

32.197.46.207.in-addr.arpa domain name pointer msdnchallenge.com.
32.197.46.207.in-addr.arpa domain name pointer mobileservices.info.
32.197.46.207.in-addr.arpa domain name pointer windowsxp.com.gt.
.
.
.
32.197.46.207.in-addr.arpa domain name pointer windowsxp.org.mu.
32.197.46.207.in-addr.arpa domain name pointer windowsruby.com.pl.
32.197.46.207.in-addr.arpa domain name pointer windowsruby.com.sg.

I tried to update the MaxLabelLength, which is bad and I should not do that and still not working

Dnsruby::Name::Label::MaxLabelLength = 2000

How I may fix this?

Memleack

Just run this code and get memleak: http://pastebin.com/xq3EbBbq
dnsruby produces a lot of strange classes for every request and theese classes are unfree in ruby, because you can't free class definition

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.