Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2287

Function to determine if given ip is in an ip range



    • Type: Task
    • Status: Done
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.10.0
    • Component/s: Built-in functions
    • Labels:


      We have the iprange() function which helps to tell us if a host is in a subnet, but it is also useful to know if a given ip is in a range. For example it is not uncommon to have multiple interfaces on a host. Being able to see if a given ip is in range allows us to narrow that knowledge to determine if a specific interface is part of a specific network.

      This can be used to adjust network settings for that interface. Another use case is to be able to lookup data based on a given interfaces ip being within a subnet range. For example, I might have a list of subnets that list country. But I may have a host that has an interface on two subnets that are assigned to different countries. What I really want to be able to do in this case is to check if sys.ipv4 or sys.ipv4[eth0] is within a given subnet. This would allow me to identify my "primary" country.

      Perhaps ip_in_range(ip, range)

      Where I could use it like this:

      string => "$(data[$(subnets)][country])"
      if => ip_in_range( $(sys.ipv4), $(subnets) );




            • Assignee:
              a10003 Eystein Maloy Stenberg
              a10042 Nick Anderson
            • Votes:
              0 Vote for this issue
              3 Start watching this issue


              • Created: