You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1011 B
Java
32 lines
1011 B
Java
|
3 months ago
|
package com.rehome.getremoteipjpa.utils;
|
||
|
|
|
||
|
|
import jakarta.servlet.http.HttpServletRequest;
|
||
|
|
import org.springframework.boot.autoconfigure.amqp.RabbitConnectionDetails;
|
||
|
|
|
||
|
|
public class IPUtils {
|
||
|
|
|
||
|
|
public static RabbitConnectionDetails.Address address;
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* getRemoteIP:获取远程请求客户端的外网IP <br/>
|
||
|
|
*
|
||
|
|
* @param request
|
||
|
|
* 请求实体对象
|
||
|
|
* @return ip 外网ip<br/>
|
||
|
|
*/
|
||
|
|
public static String getRemoteIP(HttpServletRequest request) {
|
||
|
|
String ip = request.getHeader("x-forwarded-for");
|
||
|
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||
|
|
ip = request.getHeader("Proxy-Client-IP");
|
||
|
|
}
|
||
|
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||
|
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||
|
|
}
|
||
|
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||
|
|
ip = request.getRemoteAddr();
|
||
|
|
}
|
||
|
|
return ip;
|
||
|
|
}
|
||
|
|
}
|