如何使用Java读取所有网卡 [英] How to read all network cards with java

查看:532
本文介绍了如何使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆