Class: Ronin::Support::Network::ASN::Record

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

Overview

Represents an individual ASN record.

Since:

  • 1.0.0

Direct Known Subclasses

DNSRecord

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, range, country_code, name) ⇒ Record

Initializes the record.

Parameters:

Since:

  • 1.0.0



63
64
65
66
67
68
# File 'lib/ronin/support/network/asn/record.rb', line 63

def initialize(number,range,country_code,name)
  @number       = number
  @range        = range
  @country_code = country_code
  @name         = name
end

Instance Attribute Details

#country_codeString? (readonly)

The country code of the ASN record.

Returns:

Since:

  • 1.0.0



41
42
43
# File 'lib/ronin/support/network/asn/record.rb', line 41

def country_code
  @country_code
end

#nameString? (readonly)

The name of the ASN record.

Returns:

Since:

  • 1.0.0



46
47
48
# File 'lib/ronin/support/network/asn/record.rb', line 46

def name
  @name
end

#numberInteger (readonly) Also known as: to_i

The ASN number.

Returns:

Since:

  • 1.0.0



31
32
33
# File 'lib/ronin/support/network/asn/record.rb', line 31

def number
  @number
end

#rangeIPRange::CIDR, IPRange::Range (readonly)

The IP range of the ASN record.

Returns:

Since:

  • 1.0.0



36
37
38
# File 'lib/ronin/support/network/asn/record.rb', line 36

def range
  @range
end

Instance Method Details

#==(other) ⇒ Boolean

Compares the record to another object.

Parameters:

  • other (Object)

    The other object to compare to.

Returns:

  • (Boolean)

Since:

  • 1.0.0



140
141
142
143
144
145
146
# File 'lib/ronin/support/network/asn/record.rb', line 140

def ==(other)
  self.class == other.class &&
    @number       == other.number &&
    @range        == other.range &&
    @country_code == other.country_code &&
    @name         == other.name
end

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

Enumerates over every IP within the ASN range.

Yields:

  • (ip)

Yield Parameters:

Returns:

  • (Enumerator)

Since:

  • 1.0.0



128
129
130
# File 'lib/ronin/support/network/asn/record.rb', line 128

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

#include?(ip) ⇒ Boolean

Determines if the IP belongs to the ASN range.

Parameters:

Returns:

  • (Boolean)

Since:

  • 1.0.0



115
116
117
# File 'lib/ronin/support/network/asn/record.rb', line 115

def include?(ip)
  @range.include?(ip)
end

#ipv4?Boolean

Determines if the ASN record has an IPv4 IP range.

Returns:

  • (Boolean)

Since:

  • 1.0.0



95
96
97
# File 'lib/ronin/support/network/asn/record.rb', line 95

def ipv4?
  @range.ipv4?
end

#ipv6?Boolean

Determines if the ASN record has an IPv6 IP range.

Returns:

  • (Boolean)

Since:

  • 1.0.0



104
105
106
# File 'lib/ronin/support/network/asn/record.rb', line 104

def ipv6?
  @range.ipv6?
end

#not_routed?Boolean

Determines if the ASN is not routed.

Returns:

  • (Boolean)

Since:

  • 1.0.0



86
87
88
# File 'lib/ronin/support/network/asn/record.rb', line 86

def not_routed?
  @number == 0
end

#routed?Boolean

Determines if the ASN is routed.

Returns:

  • (Boolean)

Since:

  • 1.0.0



77
78
79
# File 'lib/ronin/support/network/asn/record.rb', line 77

def routed?
  @number != 0
end

#to_sString

Converts the record into a humanly readable String.

Returns:

Since:

  • 1.0.0



155
156
157
158
159
160
161
# File 'lib/ronin/support/network/asn/record.rb', line 155

def to_s
  if routed?
    "#{range} AS#{number} (#{country_code}) #{name}"
  else
    "#{range} Not routed"
  end
end