mercredi 4 novembre 2015

read linux config files using java

I need some help in my project a build application in Java that reads config files from a Linux system. I want to show some value from these files like this:

//the code in config file
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.128 192.168.1.254;  
option subnet-mask              255.255.255.0;
option broadcast-address        192.168.1.255;#comment here
....
}

In the application, it should be print something like this:

  network 1 : 192.168.1.0/24
  range : from 192.168.1.128 to 192.168.1.254
  mask : 255.255.255.0
  broadcast : 192.168.1.255

So I need to read the value from specified args like "option subnet-mask" to the end of the line is ";" and return just the value "255.255.255.0". and if there is a comment "#", don't do anything just go to next line. Each configuration starts from "{" and ends at "}". So when it comes to "}" it should stop and go for the next network if there.

Aucun commentaire:

Enregistrer un commentaire