Class: Itdis

Inherits:
Object
  • Object
show all
Includes:
ItdisVersion
Defined in:
lib/itdis.rb

Overview

The class used for resolving domains

Constant Summary

Constants included from ItdisVersion

ItdisVersion::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, domains) ⇒ Itdis

A new instance of resolver

Parameters:

  • scope (Array<String>)

    see #scope

  • domains (Array<String>)


56
57
58
59
# File 'lib/itdis.rb', line 56

def initialize(scope, domains)
  self.scope = scope
  self.domains = domains
end

Instance Attribute Details

#domainsArray<String> #domains=(domains) ⇒ Array<String>

Overloads:

  • #domainsArray<String>

    Get domains

    Examples:

    ['example.org', 'example.com']

    Returns:

    • (Array<String>)

      Array of domains that must be checked

  • #domains=(domains) ⇒ Array<String>

    Set domains

    Parameters:

    • domains (Array<String>)

      Array of domains that must be checked

    Returns:

    • (Array<String>)

      Array of domains that must be checked



39
40
41
# File 'lib/itdis.rb', line 39

def domains
  @domains
end

#scopeArray<String> #scope( = scope) ⇒ Array<String>

Overloads:

  • #scopeArray<String>

    Get the scope

    Examples:

    ['192.168.0.42']

    Returns:

    • (Array<String>)

      Array of IP addresses that are in the scope

  • #scope( = scope) ⇒ Array<String>

    Set the scope

    Parameters:

    • scope (Array<String>)

      Array of IP addresses that are in the scope

    Returns:

    • (Array<String>)

      Array of IP addresses that are in the scope



26
27
28
# File 'lib/itdis.rb', line 26

def scope
  @scope
end

Instance Method Details

#checkHash

Check if the domains of the instance are in the scope

Examples:

irb(main):001:0> Itdis.new(['127.0.0.1', '205.251.242.103'],['amazon.com']).check
=> {"amazon.com"=>{"205.251.242.103"=>true, "176.32.103.205"=>false, "176.32.98.166"=>false}}

Returns:

  • (Hash)

    the domain and associated IPs checked. true if in scope false else.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/itdis.rb', line 67

def check
  checked = {}
  @domains.each do |domain|
    ips = {}
    Resolv.each_address(domain.chomp) do |ip|
      is_in_scope = false
      is_in_scope = true if @scope.include?(ip)
      ips.store(ip, is_in_scope)
    end
    checked.store(domain, ips)
  end
  return checked
end