java 获取本地ip 获取宽带ip
public static void main(String[] args) { try { Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces(); while (netInterfaces.hasMoreElements()) { NetworkInterface nif = netInterfaces.nextElement(); Enumeration<InetAddress> iparray = nif.getInetAddresses(); while (iparray.hasMoreElements()) { System.out.println("IP:"+ iparray.nextElement().getHostAddress()); } } } catch (Exception e) { System.out.println(e.getMessage()); } }
?