java获取本地网卡信息

来源:互联网 发布:淘宝上买凤楼信息暗语 编辑:程序博客网 时间:2024/05/06 05:51
public static void main(String args[]) throws SocketException {
Enumeration<NetworkInterface> nets = NetworkInterface
.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets))
displayInterfaceInformation(netint);
}


static void displayInterfaceInformation(NetworkInterface netint)
throws SocketException {
System.out.printf("Display name: %s\n", netint.getDisplayName());
System.out.printf("Name: %s\n", netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
System.out.printf("InetAddress: %s\n", inetAddress);
}
System.out.printf("\n");
}
0 0
原创粉丝点击