学习java套接字编程之 打印网络设备信息
package vb2005xu.net.display;
import java.net.*;
import java.util.Enumeration;
/**
* 打印 本地网络设备的信息
*
* @author KenXu 2010-8-20
*/
public class InetAdderssesInfo {
public static void run() throws SocketException {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()){
NetworkInterface networkInterface = networkInterfaces.nextElement() ;
String $outInfo = "********* " + networkInterface.getName() + " *********" + "\n" ;
$outInfo += "设备名称: " + networkInterface.getDisplayName() + "\n" ;
System.out.println($outInfo+"\n");
}
}
public static void main(String[] args) {
try {
InetAdderssesInfo.run();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
本机输出结果:
写道
********* lo *********
设备名称: Software Loopback Interface 1
********* net0 *********
设备名称: WAN Miniport (SSTP)
********* net1 *********
设备名称: WAN Miniport (IKEv2)
********* net2 *********
设备名称: WAN Miniport (L2TP)
********* net3 *********
设备名称: WAN Miniport (PPTP)
********* ppp0 *********
设备名称: WAN Miniport (PPPOE)
********* eth0 *********
设备名称: WAN Miniport (IPv6)
********* eth1 *********
设备名称: WAN Miniport (Network Monitor)
********* eth2 *********
设备名称: WAN Miniport (IP)
********* ppp1 *********
设备名称: RAS Async Adapter
********* eth3 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller
********* eth4 *********
设备名称: WAN Miniport (IP) - Teefer2 Miniport
********* eth5 *********
设备名称: WAN Miniport (IPv6) - Teefer2 Miniport
********* eth6 *********
设备名称: WAN Miniport (Network Monitor) - Teefer2 Miniport
********* eth7 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller - Teefer2 Miniport
********* eth8 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller
********* eth9 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller - Teefer2 Miniport
********* net4 *********
设备名称: Teredo Tunneling Pseudo-Interface
********* eth10 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller-QoS Packet Scheduler-0000
********* eth11 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller-WFP LightWeight Filter-0000
********* eth12 *********
设备名称: WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
********* eth13 *********
设备名称: WAN Miniport (IP)-QoS Packet Scheduler-0000
********* eth14 *********
设备名称: WAN Miniport (IPv6)-QoS Packet Scheduler-0000
设备名称: Software Loopback Interface 1
********* net0 *********
设备名称: WAN Miniport (SSTP)
********* net1 *********
设备名称: WAN Miniport (IKEv2)
********* net2 *********
设备名称: WAN Miniport (L2TP)
********* net3 *********
设备名称: WAN Miniport (PPTP)
********* ppp0 *********
设备名称: WAN Miniport (PPPOE)
********* eth0 *********
设备名称: WAN Miniport (IPv6)
********* eth1 *********
设备名称: WAN Miniport (Network Monitor)
********* eth2 *********
设备名称: WAN Miniport (IP)
********* ppp1 *********
设备名称: RAS Async Adapter
********* eth3 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller
********* eth4 *********
设备名称: WAN Miniport (IP) - Teefer2 Miniport
********* eth5 *********
设备名称: WAN Miniport (IPv6) - Teefer2 Miniport
********* eth6 *********
设备名称: WAN Miniport (Network Monitor) - Teefer2 Miniport
********* eth7 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller - Teefer2 Miniport
********* eth8 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller
********* eth9 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller - Teefer2 Miniport
********* net4 *********
设备名称: Teredo Tunneling Pseudo-Interface
********* eth10 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller-QoS Packet Scheduler-0000
********* eth11 *********
设备名称: Marvell Yukon 88E8057 PCI-E Gigabit Ethernet Controller-WFP LightWeight Filter-0000
********* eth12 *********
设备名称: WAN Miniport (Network Monitor)-QoS Packet Scheduler-0000
********* eth13 *********
设备名称: WAN Miniport (IP)-QoS Packet Scheduler-0000
********* eth14 *********
设备名称: WAN Miniport (IPv6)-QoS Packet Scheduler-0000