Class: Ronin::Support::Network::IPRange
- Inherits:
-
Object
- Object
- Ronin::Support::Network::IPRange
- Defined in:
- lib/ronin/support/network/ip_range.rb,
lib/ronin/support/network/ip_range/cidr.rb,
lib/ronin/support/network/ip_range/glob.rb,
lib/ronin/support/network/ip_range/range.rb
Overview
Represents an IP range.
Examples
Enumerating over a CIDR range:
IPRange.each('10.0.0.1/24') { |ip| puts ip }
# 10.0.0.0
# 10.0.0.1
# 10.0.0.2
# ...
# 10.0.0.254
# 10.0.0.255
Enumerating over a IP-glob range:
IPRange.each('10.0.1-3.*') { |ip| puts ip }
# 10.0.1.1
# 10.0.1.2
# ...
# 10.0.1.253
# 10.0.1.254
# ...
# 10.0.2.1
# 10.0.2.2
# ...
# 10.0.2.253
# 10.0.2.254
# ...
# 10.0.3.1
# 10.0.3.2
# ...
# 10.0.3.253
# 10.0.3.254
Defined Under Namespace
Class Method Summary collapse
-
.cidr?(string) ⇒ Boolean
Determines if the IP range is a CIDR range.
-
.each(string) {|ip| ... } ⇒ Enumerator
Enumerates over each IP address that is included in the addresses netmask.
-
.glob?(string) ⇒ Boolean
Determines if the IP range is a IP-glob range.
-
.parse(string) ⇒ IPRange
Alias for new.
Instance Method Summary collapse
-
#each {|ip| ... } ⇒ Enumerator
Enumerates over each IP address that is included in the addresses netmask.
-
#initialize(string) ⇒ IPRange
constructor
Initializes the IP range.
-
#inspect ⇒ String
Inspects the IP range.
-
#ipv4? ⇒ Boolean
Determines if the IP range is IPv4.
-
#ipv6? ⇒ Boolean
Determines if the IP range is IPv6.
-
#string ⇒ String
The IP range string.
-
#to_s ⇒ String
Converts the IP range back to a String.
Constructor Details
Class Method Details
.cidr?(string) ⇒ Boolean
Determines if the IP range is a CIDR range.
162 163 164 |
# File 'lib/ronin/support/network/ip_range.rb', line 162 def self.cidr?(string) !glob?(string) end |
.each(string) {|ip| ... } ⇒ Enumerator
Enumerates over each IP address that is included in the addresses netmask. Supports both IPv4 and IPv6 addresses.
149 150 151 |
# File 'lib/ronin/support/network/ip_range.rb', line 149 def self.each(string,&block) new(string).each(&block) end |
.glob?(string) ⇒ Boolean
Determines if the IP range is a IP-glob range.
175 176 177 |
# File 'lib/ronin/support/network/ip_range.rb', line 175 def self.glob?(string) string.include?('*') || string.include?(',') || string.include?('-') end |
Instance Method Details
#each {|ip| ... } ⇒ Enumerator
Enumerates over each IP address that is included in the addresses netmask. Supports both IPv4 and IPv6 addresses.
254 255 256 |
# File 'lib/ronin/support/network/ip_range.rb', line 254 def each(&block) @range.each(&block) end |
#inspect ⇒ String
Inspects the IP range.
275 276 277 |
# File 'lib/ronin/support/network/ip_range.rb', line 275 def inspect "#<#{self.class}: #{@range.string}>" end |
#ipv4? ⇒ Boolean
Determines if the IP range is IPv4.
193 194 195 |
# File 'lib/ronin/support/network/ip_range.rb', line 193 def ipv4? @range.ipv4? end |
#ipv6? ⇒ Boolean
Determines if the IP range is IPv6.
202 203 204 |
# File 'lib/ronin/support/network/ip_range.rb', line 202 def ipv6? @range.ipv6? end |
#string ⇒ String
The IP range string.
184 185 186 |
# File 'lib/ronin/support/network/ip_range.rb', line 184 def string @range.string end |
#to_s ⇒ String
Converts the IP range back to a String.
266 267 268 |
# File 'lib/ronin/support/network/ip_range.rb', line 266 def to_s @range.to_s end |