使用 java.net.InterfaceAddress 获取网卡信息
发布时间:2020-05-24 16:17:51 所属栏目:Java 来源:互联网
导读:使用 java.net.InterfaceAddress 获取网卡信息
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
public class NetworkParameterDemo {
public static void main(String[] args) throws Exception {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface ni = en.nextElement();
printParameter(ni);
}
}
public static void printParameter(NetworkInterface ni) throws SocketException {
System.out.println(" Name = " + ni.getName());
System.out.println(" Display Name = " + ni.getDisplayName());
System.out.println(" Is up = " + ni.isUp());
System.out.println(" Support multicast = " + ni.supportsMulticast());
System.out.println(" Is loopback = " + ni.isLoopback());
System.out.println(" Is virtual = " + ni.isVirtual());
System.out.println(" Is point to point = " + ni.isPointToPoint());
System.out.println(" Hardware address = " + ni.getHardwareAddress());
System.out.println(" MTU = " + ni.getMTU());
System.out.println("nList of Interface Addresses:");
List<InterfaceAddress> list = ni.getInterfaceAddresses();
Iterator<InterfaceAddress> it = list.iterator();
while (it.hasNext()) {
InterfaceAddress ia = it.next();
System.out.println(" Address = " + ia.getAddress());
System.out.println(" Broadcast = " + ia.getBroadcast());
System.out.println(" Network prefix length = " + ia.getNetworkPrefixLength());
System.out.println("");
}
}
}
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
