Module: JamfRubyExtensions::IPAddr::Utils
- Included in:
- IPAddr
- Defined in:
- lib/jamf/ruby_extensions/ipaddr/utils.rb
Instance Method Summary collapse
-
#j_cidr_from_ends(starting, ending) ⇒ FixNum
(also: #jss_cidr_from_ends)
Given starting and ending IPv4 IP addresses (either Strings or IPAddrs) return the CIDR notation routing prefix mask.
-
#j_ending_address(starting, cidr) ⇒ IPAddr
(also: #jss_ending_address)
Convert a starting address (either String or IPAddr) and a CIDR notation routing prefix mask into the IPv4 address of at the end of the range of addresses.
-
#j_masked_v4addr(starting, ending) ⇒ IPAddr
(also: #jss_masked_v4addr)
Convert starting and ending IPv4 IP addresses (either Strings or IPAddrs) into a single masked IPv4 IPAddr.
Instance Method Details
#j_cidr_from_ends(starting, ending) ⇒ FixNum Also known as: jss_cidr_from_ends
Given starting and ending IPv4 IP addresses (either Strings or IPAddrs) return the CIDR notation routing prefix mask
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jamf/ruby_extensions/ipaddr/utils.rb', line 59 def j_cidr_from_ends(starting,ending) starting = IPAddr.new(starting) unless starting.kind_of? IPAddr ending = IPAddr.new(ending) unless ending.kind_of? IPAddr ### how many possible addresses in the range? num_addrs = ending.to_i - starting.to_i + 1 ### convert the number of possible addresses to ### binary then subtract the number of bits from ### the full length of an IPv4 addr ### (32 bits) and that gives the CIDR prefix return 32 - num_addrs.to_s(2).length + 1 end |
#j_ending_address(starting, cidr) ⇒ IPAddr Also known as: jss_ending_address
Convert a starting address (either String or IPAddr) and a CIDR notation routing prefix mask into the IPv4 address of at the end of the range of addresses.
89 90 91 |
# File 'lib/jamf/ruby_extensions/ipaddr/utils.rb', line 89 def j_ending_address(starting, cidr) IPAddr.new( "#{starting}/#{cidr}").to_range.max end |
#j_masked_v4addr(starting, ending) ⇒ IPAddr Also known as: jss_masked_v4addr
Convert starting and ending IPv4 IP addresses (either Strings or IPAddrs) into a single masked IPv4 IPAddr
42 43 44 |
# File 'lib/jamf/ruby_extensions/ipaddr/utils.rb', line 42 def j_masked_v4addr(starting,ending) IPAddr.new "#{starting}/#{self.j_cidr_from_ends(starting,ending)}" end |