获取无线局域网适配器IP 发表于 2018-07-24 | | 阅读次数: RT,嗯! 点击显/隐 123456789101112131415161718192021222324252627282930313233343536373839404142import java.net.InetAddress;import java.net.NetworkInterface;import java.util.ArrayList;import java.util.Enumeration;import java.util.List;public class mc_07241 { public static void main(String[] args) { getLocalIP(); } public static List<String> getLocalIP() { List<String> ipList = new ArrayList<String>(); InetAddress ip = null; try { Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface .getNetworkInterfaces(); while (netInterfaces.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement(); if (ni.getName().indexOf("wlan") == -1) continue; // 遍历所有ip Enumeration<InetAddress> ips = ni.getInetAddresses(); while (ips.hasMoreElements()) { ip = (InetAddress) ips.nextElement(); if (null == ip || "".equals(ip)) { continue; } String sIP = ip.getHostAddress(); if (sIP == null || sIP.indexOf(":") > -1) { continue; } ipList.add(sIP); System.out.println(sIP); } } } catch (Exception e) { e.printStackTrace(); } return ipList; }} Your support will encourage me to continue to create! Donate WeChat Pay Alipay