Java获取当前ip地址

作者: adm 分类: java 发布时间: 2021-07-05 15:12

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);
}
}

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!