|
...
|
...
|
@@ -4,7 +4,10 @@ import com.ruoyi.common.utils.StringUtils; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.NetworkInterface;
|
|
|
|
import java.net.SocketException;
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取IP方法
|
|
...
|
...
|
@@ -211,6 +214,33 @@ public class IpUtils |
|
|
|
return "127.0.0.1";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getLocalHost()
|
|
|
|
{
|
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
try {
|
|
|
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
|
|
|
while (interfaces.hasMoreElements()) {
|
|
|
|
NetworkInterface networkInterface = interfaces.nextElement();
|
|
|
|
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
|
|
|
|
while (addresses.hasMoreElements()) {
|
|
|
|
InetAddress address = addresses.nextElement();
|
|
|
|
if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) {
|
|
|
|
if(stringBuffer.length() != 0 )
|
|
|
|
{
|
|
|
|
stringBuffer.append(":");
|
|
|
|
}
|
|
|
|
stringBuffer.append(address.getHostAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SocketException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return stringBuffer.toString();
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
System.out.println(getLocalHost());
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 获取主机名
|
|
|
|
*
|
...
|
...
|
|