Class: MetasploitDataModels::IPAddress::V4::Segment::Single

Inherits:
Metasploit::Model::Base
  • Object
show all
Extended by:
Match::Child
Includes:
Comparable
Defined in:
app/models/metasploit_data_models/ip_address/v4/segment/single.rb

Overview

A segment number in an IPv4 address or the Nmap::Range#begin or Nmap::Range#send.

Constant Summary collapse

BITS =

Number of bits in a IPv4 segment

8
LIMIT =

Limit that #value can never reach

1 << BITS
MAXIMUM =

Maximum segment #value

LIMIT - 1
MINIMUM =

Minimum segment #value

0
REGEXP =

Regular expression for a segment (octet) of an IPv4 address in decimal dotted notation.

/(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject

Returns the value of attribute value.



38
39
40
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 38

def value
  @value
end

Class Method Details

.bitsInteger

Number of bits in a IPv4 segment

Returns:

  • (Integer)


58
59
60
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 58

def self.bits
  BITS
end

Instance Method Details

#<=>(other) ⇒ 1, ...

Compare this segment to other.

Parameters:

  • other (#value)

    another segent to compare against.

Returns:

  • (1)

    if this segment is greater than other.

  • (0)

    if this segment is equal to other.

  • (-1)

    if this segment is less than other.



72
73
74
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 72

def <=>(other)
  value <=> other.value
end

#add_with_carry(other, carry = 0) ⇒ Array<(MetasploitDataModels::IPAddress::V4::Segment::Single, Integer)>

Full add (as in full adder) two (this segment and other) segments and a carry from the previous #add_with_carry.

Parameters:

  • other (MetasploitDataModels:IPAddress::V4::Segment::Single)

    segment to add to this segment.

  • carry (Integer) (defaults to: 0)

    integer to add to this segment and other segment from a previous call to #add_with_carry for lower segments.

Returns:



85
86
87
88
89
90
91
92
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 85

def add_with_carry(other, carry=0)
  improper_value = self.value + other.value + carry
  proper_value = improper_value % LIMIT
  carry = improper_value / LIMIT
  segment = self.class.new(value: proper_value)

  [segment, carry]
end

#succMetasploitDataModels::IPAddress::V4::Segment::Single?

The succeeding segment. Used in Ranges when walking the Range.

Returns:



98
99
100
101
102
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 98

def succ
  if value.respond_to? :succ
    self.class.new(value: value.succ)
  end
end