Java获取当前ip地址
Java获取当前ip地址
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddressInUse {
public static void main(String[] args){
String ip=null; try { InetAddress ip4 = Inet4Address.getLocalHost(); ip=ip4.getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); }
System.out.println(ip);
}
}