Class: Ronin::Support::Network::IPRange::Glob
- Inherits:
-
Object
- Object
- Ronin::Support::Network::IPRange::Glob
- Includes:
- Enumerable
- Defined in:
- lib/ronin/support/network/ip_range/glob.rb
Overview
Instance Attribute Summary collapse
-
#string ⇒ String
readonly
The IP glob string.
Class Method Summary collapse
-
.each(string) {|ip| ... } ⇒ self
Enumerates over the IP-glob range.
-
.parse(string) ⇒ Glob
Alias for new.
Instance Method Summary collapse
-
#each {|ip| ... } ⇒ self
Enumerates over the IP-glob range.
-
#initialize(string) ⇒ Glob
constructor
Initializes and parses the IP-glob range.
-
#inspect ⇒ String
Inspects the IP-glob range.
-
#ipv4? ⇒ Boolean
Determines if the IP-glob range is IPv4.
-
#ipv6? ⇒ Boolean
Determines if the IP-glob range is IPv6.
-
#to_s ⇒ String
Converts the IP-glob range back into a String.
Methods included from Enumerable
Constructor Details
#initialize(string) ⇒ Glob
Initializes and parses the IP-glob range.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 69 def initialize(string) @string = string if @string.include?(':') # IPv6 @version = 6 @separator = ':' @base = 16 @formatter = method(:format_ipv6_address) else # IPv4 @version = 4 @separator = '.' @base = 10 @formatter = method(:format_ipv4_address) end @ranges = @string.split(@separator).map do |segment| case segment when '*' then (1..254) when /,/ then parse_list(segment) when /-/ then parse_range(segment) else [segment] end end end |
Instance Attribute Details
#string ⇒ String (readonly)
The IP glob string.
61 62 63 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 61 def string @string end |
Class Method Details
.each(string) {|ip| ... } ⇒ self
Enumerates over the IP-glob range.
147 148 149 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 147 def self.each(string,&block) new(string).each(&block) end |
Instance Method Details
#each {|ip| ... } ⇒ self
Enumerates over the IP-glob range.
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 206 def each return enum_for(__method__) unless block_given? # cycle through the address ranges @ranges.comprehension do |address| yield @formatter.call(address) end return self end |
#inspect ⇒ String
Inspects the IP-glob range.
231 232 233 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 231 def inspect "#<#{self.class}: #{@string}>" end |
#ipv4? ⇒ Boolean
Determines if the IP-glob range is IPv4.
156 157 158 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 156 def ipv4? @version == 4 end |
#ipv6? ⇒ Boolean
Determines if the IP-glob range is IPv6.
165 166 167 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 165 def ipv6? @version == 6 end |
#to_s ⇒ String
Converts the IP-glob range back into a String.
222 223 224 |
# File 'lib/ronin/support/network/ip_range/glob.rb', line 222 def to_s @string end |