class Ronin::Support::Network::ASN::RecordSet

A sub-set of ASN records.

Attributes

records[R]

The records in the record set.

@return [Array<Record>, Enumerator::Lazy<Record>]

Public Class Methods

new(records=[]) click to toggle source

Initializes the record-set.

@param [Enumerator::Lazy<Record>] records

The optional records to initialize the record set with.

@api private

# File lib/ronin/support/network/asn/record_set.rb, line 45
def initialize(records=[])
  @records = records
end

Public Instance Methods

<<(record) click to toggle source

Adds a record to the record-set.

@param [Record] record

@return [self]

@api private

# File lib/ronin/support/network/asn/record_set.rb, line 58
def <<(record)
  @records << record
  return self
end
countries() click to toggle source

Retruns all country codes within the record set.

@return [Set<String>]

# 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) click to toggle source

Selects all records with the matching country code.

@param [String] country_code

The two-letter country code.

@return [RecordSet]

The new sub-set of records.
# 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(&block) click to toggle source

Enumerates over each IP within all of the records.

@yield [record]

@yieldparam [Record] record

@return [Enumerator]

# File lib/ronin/support/network/asn/record_set.rb, line 72
def each(&block)
  @records.each(&block)
end
include?(ip) click to toggle source

Determines if the IP belongs to any of the records.

@param [IPAddr, String] ip

@return [Boolean]

# File lib/ronin/support/network/asn/record_set.rb, line 177
def include?(ip)
  !ip(ip).nil?
end
ip(ip) click to toggle source

Finds the ASN record for the given IP address.

@param [IP, IPaddr, String] ip

The IP address to search for.

@return [Record, nil]

The ASN record for the IP address or `nil` if none could be found.
# File lib/ronin/support/network/asn/record_set.rb, line 166
def ip(ip)
  find { |record| record.range.include?(ip) }
end
ipv4() click to toggle source

Selects only the records with IPv4 ranges.

@return [RecordSet]

The new sub-set of records.
# File lib/ronin/support/network/asn/record_set.rb, line 143
def ipv4
  RecordSet.new(lazy.select(&:ipv4?))
end
ipv6() click to toggle source

Selects only the records with IPv6 ranges.

@return [RecordSet]

The new sub-set of records.
# File lib/ronin/support/network/asn/record_set.rb, line 153
def ipv6
  RecordSet.new(lazy.select(&:ipv6?))
end
length() click to toggle source

The number of records within the record-set.

@return [Integer]

# File lib/ronin/support/network/asn/record_set.rb, line 212
def length
  @records.length
end
name(name) click to toggle source

Selects all records with the matching company name.

@param [String] name

The company name to search for.

@return [RecordSet]

The new sub-set of records.
# File lib/ronin/support/network/asn/record_set.rb, line 201
def name(name)
  RecordSet.new(
    lazy.select { |record| record.name == name }
  )
end
names() click to toggle source

Returns all company names within the record-set.

@return [Set<String>]

# 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) click to toggle source

Selects all records with the matching AS number.

@param [Integer] number

The AS number.

@return [RecordSet]

The new sub-set of records.
# File lib/ronin/support/network/asn/record_set.rb, line 96
def number(number)
  RecordSet.new(
    lazy.select { |record| record.number == number }
  )
end
numbers() click to toggle source

Returns all AS numbers within the record set.

@return [Set<Integer>]

# File lib/ronin/support/network/asn/record_set.rb, line 81
def numbers
  set = Set.new
  each { |record| set << record.number }
  set
end
ranges() click to toggle source

Returns all IP ranges within the record set.

@return [Array<IPRange::Range>]

# File lib/ronin/support/network/asn/record_set.rb, line 133
def ranges
  map(&:range)
end
to_a() click to toggle source

Converts the record-set to an Array of records.

@return [Array<Range>]

# File lib/ronin/support/network/asn/record_set.rb, line 221
def to_a
  @records.to_a
end