如何使用Java读取所有网卡 [英] How to read all network cards with java
问题描述
我想在系统中(使用Java)查找所有网卡和网络接口.因此,更确切地说,我想从ifconfig
命令(在Linux中)获得整个输出,而在Java中.我知道是否使用NetworkInterface.getNetworkInterfaces()
将仅返回已配置的网络接口.
I want to lookup in my system (using java) for all network cards and network interfaces. So, more exactly, I want to get the whole output from ifconfig
command (in Linux) but in Java. I know if I use NetworkInterface.getNetworkInterfaces()
will return only configured network interfaces.
A rough approach I found at this link. It is OK, but I'm interested if there are other possibilities on this.
推荐答案
您可以在Windows上使用Runtime.getRuntime().exec("ipconfig")
,在Linux上使用Runtime.getRuntime().exec("ifconfig")
在Java中获取ifconfig结果
You can use Runtime.getRuntime().exec("ipconfig")
for Windows and Runtime.getRuntime().exec("ifconfig")
for linux to get ifconfig result in java
没有办法在100%Java中获得详细信息.您可以执行命令或编写JNI.
There is no way to get to the gory details here in 100% Java. You can either execute commands or write JNI.
这篇关于如何使用Java读取所有网卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!