Java获取当前服务器ip

Java获取当前服务器ip

参考 https://www.cnblogs.com/-llf/p/11769799.html

import java.net.InetAddress;
import java.net.UnknownHostException;

public class ServerIpUtil {

    public static String getLocalServerIp() {
        try {
            InetAddress inetAddress = InetAddress.getLocalHost();
            String localServerIp = inetAddress.getHostAddress();
            return localServerIp;
        } catch (UnknownHostException e) {
            LoggerUtil.error(e.getMessage(), e);
            return "500";
        }
    }

}

 

posted on 2022-08-30 16:56  dreamstar  阅读(759)  评论(0编辑  收藏  举报