Class: Rex::Proto::DNS::UpstreamResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/dns/upstream_resolver.rb

Overview

This represents a single upstream DNS resolver target of one of the predefined types.

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, destination: nil, socket_options: {}) ⇒ UpstreamResolver

Returns a new instance of UpstreamResolver.

Parameters:

  • type (Symbol)

    The resolver type.

  • destination (String) (defaults to: nil)

    An optional destination, as used by some resolver types.

  • socket_options (Hash) (defaults to: {})

    Options to use for sockets when connecting to the destination, as used by some resolver types.



23
24
25
26
27
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 23

def initialize(type, destination: nil, socket_options: {})
  @type = type
  @destination = destination
  @socket_options = socket_options
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



17
18
19
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 17

def destination
  @destination
end

#socket_optionsObject (readonly)

Returns the value of attribute socket_options.



17
18
19
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 17

def socket_options
  @socket_options
end

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 17

def type
  @type
end

Class Method Details

.create_black_holeObject

Initialize a new black-hole resolver.



30
31
32
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 30

def self.create_black_hole
  self.new(Type::BLACK_HOLE)
end

.create_dns_server(destination, socket_options: {}) ⇒ Object

Initialize a new dns-server resolver.

Parameters:

  • destination (String)

    The IP address of the upstream DNS server.

  • socket_options (Hash) (defaults to: {})

    Options to use when connecting to the upstream DNS server.



38
39
40
41
42
43
44
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 38

def self.create_dns_server(destination, socket_options: {})
  self.new(
    Type::DNS_SERVER,
    destination: destination,
    socket_options: socket_options
  )
end

.create_staticObject

Initialize a new static resolver.



47
48
49
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 47

def self.create_static
  self.new(Type::STATIC)
end

.create_systemObject

Initialize a new system resolver.



52
53
54
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 52

def self.create_system
  self.new(Type::SYSTEM)
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 64

def eql?(other)
  return false unless other.is_a?(self.class)
  return false unless other.type == type
  return false unless other.destination == destination
  return false unless other.socket_options == socket_options
  true
end

#to_sObject



56
57
58
59
60
61
62
# File 'lib/rex/proto/dns/upstream_resolver.rb', line 56

def to_s
  if type == Type::DNS_SERVER
    destination.to_s
  else
    type.to_s
  end
end