[ipxe-devel] How to determine if IP belongs to specified network range (IPXE script)?

Michael Brown mcb30 at ipxe.org
Mon Oct 12 11:22:51 UTC 2015


On 11/10/15 11:23, Robert Socha wrote:
> I 'm looking for a way to determine whether the IP number belongs to a
> particular network (from a IPXE script).
>
> For example in pseudo code:
>
> if ( IP in 192.168.1.0/24) && goto dosomething
>
> I needed a ASAP solution so I created a simple patch (attached below).
>
> Is this a correct solution? Is there any way to do so with the existing
> IPXE commands ?

There is no way to do this for a general IP address / netmask pair.

However, I'm guessing that for the case of iPXE scripts, what you almost 
certainly want is to test "is *my* IP address within a particular 
network", rather than the ability to test "is an *arbitrary* IP address 
within a particular network".

If this is the case, then the simplest solution would probably be to use 
the default gateway address, which will (usually) be constant and 
predictable for a given network.  Instead of your

   isnetwork ${ip} 192.168.1.0 255.255.255.0 && goto dosomething

you could just use

   iseq ${gateway} 192.168.1.1 && goto dosomething

(assuming that your 192.168.1.0/24 network uses 192.168.1.1 as its 
default gateway).

Michael



More information about the ipxe-devel mailing list