初学者 java网络编程的问题
//如下代码
package laobao;import java.net.InetAddress;public class Demo01 { public static void main(String args[]) throws Exception{ InetAddress localAddress = InetAddress.getLocalHost(); System.out.println("本地IP :" + localAddress.getHostAddress() ); }}import java.net.InetAddress;import java.net.NetworkInterface;import java.util.Enumeration;public class GetIpsInfo { public static void main(String[] args) { Enumeration nettworkInterfaces = null; try { nettworkInterfaces = NetworkInterface.getNetworkInterfaces(); while (nettworkInterfaces.hasMoreElements()) { System.out.println("---------------------"); NetworkInterface networkInterface = (NetworkInterface) nettworkInterfaces.nextElement(); System.out.println("DisplayName = " + networkInterface.getDisplayName()); System.out.println(" Name = " + networkInterface.getName()); Enumeration inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { System.out.println("这块网卡的IP = " + ((InetAddress) inetAddresses.nextElement()).getHostAddress()); } } } catch (Exception e) { e.printStackTrace(); } System.out.println("---------------------"); }}