">
赞
踩
- <%@ page language="java" contentType="text/html; charset=UTF-8"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>获取客户端的IP地址</title>
- </head>
- <body>
- <%
- //获取HTTP头的x-forwarded-for信息
- String realIP = request.getHeader("x-forwarded-for");
- if(realIP != null && realIP.length() != 0){
- //如果有x-forwarded-for信息,而且等于unknown,则继续读取下一个信息
- while((realIP != null) && (realIP.equals("unknown"))){
- realIP = request.getHeader("x-forwarded-for");
- }
- }
- if(realIP == null || realIP.length() == 0){
- realIP = request.getHeader("Proxy-Client-IP");
- }
- if(realIP == null || realIP.length() == 0){
- realIP = request.getHeader("WL-Proxy-Client-IP");
- }
- if(realIP == null || realIP.length() == 0){
- realIP = request.getRemoteAddr();
- }
- out.println("你的IP地址是:"+ realIP);
- %>
- <br/>
- </body>
- </html>
效果图如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。