Sha256: ebdc62b7f0f591bad2168701a66d541c5a361dff5d320d8e1c2ec1c7f7726106

Contents?: true

Size: 613 Bytes

Versions: 1

Compression:

Stored size: 613 Bytes

Contents

require "reversed/version"
require "net/dns"

module Reversed
  def self.lookup(ip, timeout: 5, nameservers: nil)
    ip = ip.to_s
    unless ip.empty?
      options = {
        retry: 3,
        udp_timeout: timeout
      }
      options[:nameservers] = nameservers if nameservers
      begin
        resolver = Net::DNS::Resolver.new(options).search(ip)
        answer = resolver.answer.first || resolver.authority.first
        if answer && !answer.value.empty?
          answer.value.split(" ").first[0..-2]
        end
      rescue Net::DNS::Resolver::NoResponseError
        nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reversed-0.2.1 lib/reversed.rb