iPXE discussion forum
Parsing subnet - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: Parsing subnet (/showthread.php?tid=8207)



Parsing subnet - Yeswanth - 2016-10-18 15:44

Hi,

I have a query. I want to get the first three numbers from the subnet mask.

For example

Net0/netmask = 192.169.168.34

But i need to get first 3 digits, my output should be like 192.169.168

Thanks in advance


RE: Parsing subnet - NiKiZe - 2016-10-18 18:18

(2016-10-18 15:44)Yeswanth Wrote:  I have a query. I want to get the first three numbers from the subnet mask.

For example

Net0/netmask = 192.169.168.34

But i need to get first 3 digits, my output should be like 192.169.168

(assuming that you ment to type netX/ip and not net0/netmask, or that the mask actually is a valid mask?)
There is no way inside of iPXE (yet) to parse parts of anything. The recommended way if you really need this is to do it server side, that is doing chain http://server/script?ip=${netX/ip}
Which in turn returns something like
Code:
#!ipxe
set ippart 192.169.168

but most of the time when someone asks similar things about getting part of ip, normally it is for some kind of logic where gateway or dns would make more sense to use.

What will you use this 3octet mask for?


RE: Parsing subnet - Yeswanth - 2016-10-19 03:10

(2016-10-18 18:18)NiKiZe Wrote:  
(2016-10-18 15:44)Yeswanth Wrote:  I have a query. I want to get the first three numbers from the subnet mask.

For example

Net0/netmask = 192.169.168.34

But i need to get first 3 digits, my output should be like 192.169.168

(assuming that you ment to type netX/ip and not net0/netmask, or that the mask actually is a valid mask?)
There is no way inside of iPXE (yet) to parse parts of anything. The recommended way if you really need this is to do it server side, that is doing chain http://server/script?ip=${netX/ip}
Which in turn returns something like
Code:
#!ipxe
set ippart 192.169.168

but most of the time when someone asks similar things about getting part of ip, normally it is for some kind of logic where gateway or dns would make more sense to use.

What will you use this 3octet mask for?





Hi

Thanks for the reply

Dhcp server will assign some ip's and subnet to some boards and i need to verify that if the subnet mask iseq to the 192.168.169 (i.e the first 3 octet) then i proceeding with execution of some steps or else i will retry


RE: Parsing subnet - NiKiZe - 2016-10-19 07:15

(2016-10-19 03:10)Yeswanth Wrote:  subnet mask iseq to the 192.168.169

That is not a valid netmask!
( For reference i found this simple list of valid netmasks: http://www.unixwiz.net/techtips/netmask-ref.html )

it could be a ip address, and in that case you would probably have a static address on the gateway that you can check for instead.

IMHO a good tool for understanding netmasks is ipcalc