日期:2014-05-17 浏览次数:20724 次
try{
serverSocket = new ServerSocket(tcpPort);
}catch(IOException e){
e.printStackTrace();
}
try{
ipAddress= InetAddress.getLocalHost();
}catch(UnknownHostException e){
}
ip=ipAddress.getHostAddress();
/**
* 获取请求IP地址
* @return
*/
protected final String getIp(){
HttpServletRequest request=getRequest();
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;
}