">
当前位置:   article > 正文

获取客户端的真实IP地址_python request 获取客户端ip

python request 获取客户端ip
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html>
  4. <head>
  5. <title>获取客户端的IP地址</title>
  6. </head>
  7. <body>
  8. <%
  9. //获取HTTP头的x-forwarded-for信息
  10. String realIP = request.getHeader("x-forwarded-for");
  11. if(realIP != null && realIP.length() != 0){
  12. //如果有x-forwarded-for信息,而且等于unknown,则继续读取下一个信息
  13. while((realIP != null) && (realIP.equals("unknown"))){
  14. realIP = request.getHeader("x-forwarded-for");
  15. }
  16. }
  17. if(realIP == null || realIP.length() == 0){
  18. realIP = request.getHeader("Proxy-Client-IP");
  19. }
  20. if(realIP == null || realIP.length() == 0){
  21. realIP = request.getHeader("WL-Proxy-Client-IP");
  22. }
  23. if(realIP == null || realIP.length() == 0){
  24. realIP = request.getRemoteAddr();
  25. }
  26. out.println("你的IP地址是:"+ realIP);
  27. %>
  28. <br/>
  29. </body>
  30. </html>




效果图如下:



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/969095
推荐阅读
相关标签
  

闽ICP备14008679号