IPUtiles.java 1015 B

1234567891011121314151617181920212223242526272829303132
  1. package com.rf.fileCrack.utils;
  2. import javax.servlet.http.HttpServletRequest;
  3. /**
  4. * @author lpf
  5. * @description:
  6. * @date 2021/12/2517:59
  7. */
  8. public class IPUtiles {
  9. public static String getRealIp(HttpServletRequest request) {
  10. String ip = request.getHeader("X-Real-IP");
  11. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  12. ip = request.getHeader("X-Forwarded-For");
  13. }
  14. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  15. ip = request.getHeader("Proxy-Client-IP");
  16. }
  17. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  18. ip = request.getHeader("WL-Proxy-Client-IP");
  19. }
  20. if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  21. ip = request.getRemoteAddr();
  22. }
  23. if (ip != null && ip.contains(",")) {
  24. String[] ipArray = ip.split(",");
  25. ip = ipArray[0];
  26. }
  27. return ip;
  28. }
  29. }