Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parsing subnet
2016-10-18, 15:44
Post: #1
Parsing subnet
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
Find all posts by this user
Quote this message in a reply
2016-10-18, 18:18
Post: #2
RE: Parsing subnet
(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?

Use GitHub Discussions
VRAM bin
Visit this user's website Find all posts by this user
Quote this message in a reply
2016-10-19, 03:10
Post: #3
RE: Parsing subnet
(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
Find all posts by this user
Quote this message in a reply
2016-10-19, 07:15
Post: #4
RE: Parsing subnet
(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

Use GitHub Discussions
VRAM bin
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 4 Guest(s)