Method: Jamf::NetworkSegment.network_segments_for_ip
- Defined in:
- lib/jamf/api/classic/api_objects/network_segment.rb
.network_segments_for_ip(ipaddr, refresh = false, api: nil, cnx: Jamf.cnx) ⇒ Array<Integer>
Find the ids of the network segments that contain a given IP address.
Even tho IPAddr.include? will take a String or an IPAddr I convert the ip to an IPAddr so that an exception will be raised if the ip isn’t a valid ip.
254 255 256 257 258 259 260 261 |
# File 'lib/jamf/api/classic/api_objects/network_segment.rb', line 254 def self.network_segments_for_ip(ipaddr, refresh = false, api: nil, cnx: Jamf.cnx) cnx = api if api # get the ip as a 32bit interger ip = IPAddr.new(ipaddr.to_s).to_i # a hash of NetSeg ids => Range<Integer> network_ranges_as_integers(refresh, cnx: cnx).select { |_id, range| range.include? ip }.keys end |