JAVA类抓取IP地址
import java.net.Inet4Address;import java.net.InetAddress;import java.net.NetworkInterface;import java.util.Enumeration;public class IPAddrFetcher { public static String getIPInfo() { String trueIp = null; try { Enumeration interfaces = NetworkInterface .getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface ni = interfaces.nextElement(); Enumeration inetAddresses = ni.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress address = inetAddresses.nextElement(); if (address instanceof Inet4Address) { if (!address.getHostAddress().equals("127.0.0.1")) trueIp = address.getHostAddress(); } } } } catch (Exception ex) { ex.printStackTrace(); } return trueIp; }}