简体   繁体   中英

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

如果您正在考虑更好,更强大的解决方案,您可能会使用SNMP(简单网络管理协议)的想法。有几个API可供使用,SNMP4J是最着名和开源的。因为多个支持SNMP操作系统甚至是交换机和路由器,在深度网络级统计中使用它可能是一个好主意。但是如果你想要一个更简单的解决方案,那么使用Sigar API,它支持许多操作系统,包括windows和linux.One Sigar的问题在于它是根据GPL许可的,禁止您将其部署在商业项目中。

You could do in native code, and use JNI. Then ship a .dll for windows, and an .so (or source code) for linux, though this probably isn't a whole lot better than the 'exec' solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM