大家好,又见面了,我是你们的朋友全栈君。
/** * 获取服务器IP地址 * @return */ public static String getServerIp(){ String SERVER_IP = null; try { String ipAddr=””; InetAddress inetAddress=InetAddress.getLocalHost(); byte[] adds = inetAddress.getAddress(); for (int i = 0; i < adds.length; i ) { if(i>0){ ipAddr =”.”; } ipAddr =adds[i]&0xFF; String hostName = inetAddress.getHostName(); System.out.println(“ipAddr:” ipAddr); System.out.println(“hostName:” hostName);
} } catch (UnknownHostException e) { e.printStackTrace(); } return SERVER_IP; }
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155683.html原文链接:https://javaforall.cn