Sha256: 8e275510d3898dbbb9db93849be74b8ec3c2e3896ff9c4e620d531887d6f8af5

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8
#
# This file is part of the devdnsd gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

def devdnsd_resolv(address = "match.dev", type = "ANY", nameserver = "127.0.0.1", port = 7771, logger = nil)
  resolver = Fiber.current
  rv = []

  port = port.to_i
  logger = Bovem::Logger.new("/dev/null", Bovem::Logger::DEBUG) if !logger
  logger.info(::Bovem::Console.replace_markers("Resolving address {mark=bright}#{address}{/mark} with type {mark=bright}#{type}{/mark} at nameserver {mark=bright}#{nameserver}{/mark}:{mark=bright}#{port.to_s}{/mark} ..."))

  answers = RubyDNS::Resolver.new([[:udp, nameserver, port], [:tcp, nameserver, port]]).query(address, "Resolv::DNS::Resource::IN::#{type}".constantize).answer

  answers.each do |answer|
    type = answer[2].class.to_s.split("::")[-1].to_sym

    name = case type
      when :MX then answer[2].exchange.to_s.gsub(/\.$/, "")
      when :CNAME then answer[2].name.to_s.gsub(/\.$/, "")
      when :NS then answer[2].name.to_s.gsub(/\.$/, "")
      when :PTR then answer[2].name.to_s.gsub(/\.$/, "")
      else answer[2].address.to_s
    end

    rv << [name, type]
  end

  rv.uniq!
  logger.info("Resolving ended with result: #{rv.inspect}")
  rv.length == 1 ? rv[0] : rv
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devdnsd-4.0.0 spec/resolver_helper.rb