Class: Ronin::Support::Network::ASN::RecordSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/support/network/asn/record_set.rb

Overview

A sub-set of ASN records.

Since:

  • 1.0.0

Direct Known Subclasses

List

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#map_hash

Constructor Details

#initialize(records = []) ⇒ RecordSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the record-set.

Parameters:

  • records (Enumerator::Lazy<Record>) (defaults to: [])

    The optional records to initialize the record set with.

Since:

  • 1.0.0



45
46
47
# File 'lib/ronin/support/network/asn/record_set.rb', line 45

def initialize(records=[])
  @records = records
end

Instance Attribute Details

#recordsArray<Record>, Enumerator::Lazy<Record> (readonly)

The records in the record set.

Returns:

Since:

  • 1.0.0



35
36
37
# File 'lib/ronin/support/network/asn/record_set.rb', line 35

def records
  @records
end

Instance Method Details

#<<(record) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a record to the record-set.

Parameters:

Returns:

  • (self)

Since:

  • 1.0.0



58
59
60
61
# File 'lib/ronin/support/network/asn/record_set.rb', line 58

def <<(record)
  @records << record
  return self
end

#countriesSet<String>

Retruns all country codes within the record set.

Returns:

Since:

  • 1.0.0



107
108
109
110
111
# File 'lib/ronin/support/network/asn/record_set.rb', line 107

def countries
  set = Set.new
  each { |record| set << record.country_code }
  set
end

#country(country_code) ⇒ RecordSet

Selects all records with the matching country code.

Parameters:

  • country_code (String)

    The two-letter country code.

Returns:

  • (RecordSet)

    The new sub-set of records.

Since:

  • 1.0.0



122
123
124
125
126
# File 'lib/ronin/support/network/asn/record_set.rb', line 122

def country(country_code)
  RecordSet.new(
    lazy.select { |record| record.country_code == country_code }
  )
end

#each {|record| ... } ⇒ Enumerator

Enumerates over each IP within all of the records.

Yields:

  • (record)

Yield Parameters:

Returns:

  • (Enumerator)

Since:

  • 1.0.0



72
73
74
# File 'lib/ronin/support/network/asn/record_set.rb', line 72

def each(&block)
  @records.each(&block)
end

#include?(ip) ⇒ Boolean

Determines if the IP belongs to any of the records.

Parameters:

Returns:

  • (Boolean)

Since:

  • 1.0.0



177
178
179
# File 'lib/ronin/support/network/asn/record_set.rb', line 177

def include?(ip)
  !ip(ip).nil?
end

#ip(ip) ⇒ Record?

Finds the ASN record for the given IP address.

Parameters:

  • ip (IP, IPaddr, String)

    The IP address to search for.

Returns:

  • (Record, nil)

    The ASN record for the IP address or nil if none could be found.

Since:

  • 1.0.0



166
167
168
# File 'lib/ronin/support/network/asn/record_set.rb', line 166

def ip(ip)
  find { |record| record.range.include?(ip) }
end

#ipv4RecordSet

Selects only the records with IPv4 ranges.

Returns:

  • (RecordSet)

    The new sub-set of records.

Since:

  • 1.0.0



143
144
145
# File 'lib/ronin/support/network/asn/record_set.rb', line 143

def ipv4
  RecordSet.new(lazy.select(&:ipv4?))
end

#ipv6RecordSet

Selects only the records with IPv6 ranges.

Returns:

  • (RecordSet)

    The new sub-set of records.

Since:

  • 1.0.0



153
154
155
# File 'lib/ronin/support/network/asn/record_set.rb', line 153

def ipv6
  RecordSet.new(lazy.select(&:ipv6?))
end

#lengthInteger

The number of records within the record-set.

Returns:

Since:

  • 1.0.0



212
213
214
# File 'lib/ronin/support/network/asn/record_set.rb', line 212

def length
  @records.length
end

#name(name) ⇒ RecordSet

Selects all records with the matching company name.

Parameters:

  • name (String)

    The company name to search for.

Returns:

  • (RecordSet)

    The new sub-set of records.

Since:

  • 1.0.0



201
202
203
204
205
# File 'lib/ronin/support/network/asn/record_set.rb', line 201

def name(name)
  RecordSet.new(
    lazy.select { |record| record.name == name }
  )
end

#namesSet<String>

Returns all company names within the record-set.

Returns:

Since:

  • 1.0.0



186
187
188
189
190
# File 'lib/ronin/support/network/asn/record_set.rb', line 186

def names
  set = Set.new
  each { |record| set << record.name }
  set
end

#number(number) ⇒ RecordSet

Selects all records with the matching AS number.

Parameters:

  • number (Integer)

    The AS number.

Returns:

  • (RecordSet)

    The new sub-set of records.

Since:

  • 1.0.0



96
97
98
99
100
# File 'lib/ronin/support/network/asn/record_set.rb', line 96

def number(number)
  RecordSet.new(
    lazy.select { |record| record.number == number }
  )
end

#numbersSet<Integer>

Returns all AS numbers within the record set.

Returns:

Since:

  • 1.0.0



81
82
83
84
85
# File 'lib/ronin/support/network/asn/record_set.rb', line 81

def numbers
  set = Set.new
  each { |record| set << record.number }
  set
end

#rangesArray<IPRange::Range>

Returns all IP ranges within the record set.

Returns:

Since:

  • 1.0.0



133
134
135
# File 'lib/ronin/support/network/asn/record_set.rb', line 133

def ranges
  map(&:range)
end

#to_aArray<Range>

Converts the record-set to an Array of records.

Returns:

Since:

  • 1.0.0



221
222
223
# File 'lib/ronin/support/network/asn/record_set.rb', line 221

def to_a
  @records.to_a
end