Sha256: d56c07929b0d631d6bae2a55bbb59b7c62ebd1de8b620efcacd416c1e59c3725

Contents?: true

Size: 668 Bytes

Versions: 2

Compression:

Stored size: 668 Bytes

Contents

# frozen_string_literal: true

require "resolv"

module RogueOne
  class Ping
    attr_reader :resolver
    attr_reader :nameserver

    def initialize(nameserver)
      @nameserver = nameserver
      @resolver = Resolv::DNS.new(nameserver: [nameserver])
      @resolver.timeouts = 5
    end

    def get_a_record
      resolver.getresource("example.com", Resolv::DNS::Resource::IN::A)
    rescue Resolv::ResolvError => _e
      nil
    end

    def pong?
      result = get_a_record
      raise Error, "DNS resolve error: there is no resopnse from #{nameserver}" unless result

      true
    end

    def self.pong?(target)
      new(target).pong?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rogue_one-0.4.2 lib/rogue_one/ping.rb
rogue_one-0.4.1 lib/rogue_one/ping.rb