Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting network info in Java on Windows and Linux platforms

I need Network configuration information in my application that is more than what java.net.NetworkInterface and java.net.InetAddress provide. I would like to include information such as Subnet, Gateway, and DNS servers, but code needs to be portable to both Windows and Linux platforms.

I have looked into doing it by doing Runtime.getRuntime().exec("ipconfig") for Windows and Runtime.getRuntime().exec("ifconfig") for Linux and parsing the results. Maybe there is a better way to do this or an open source project that I could use.

Thanks in advance for any ideas that can steer me in the right direction

like image 360
Travis Nelson Avatar asked Nov 15 '11 21:11

Travis Nelson


1 Answers

If you are thinking of a better and more robust solution,you could probably use the idea of SNMP(Simple Network Management Protocol).There are several API's available for use,SNMP4J being the most famous and open source.Since SNMP is supported across multiple Operating Systems and even switches and routers,it is probably a good idea to use it of you want in depth network level statistics.But if you want a more simple solution then use the Sigar API,which supports many OS including windows and linux.One problem with Sigar is that it is licensed under GPL which prohibits you to deploy it in a commercial project.

like image 127
Madusudanan Avatar answered Oct 30 '22 20:10

Madusudanan