String IP = httpRequest.getHeader("x-forworded-for");
if (IP != null && IP.length() != 0) {
while ((IP != null) && (IP.equals("unknow"))) {
IP = httpRequest.getHeader("x-forworded-for");
}
}
if (IP == null || IP.length() == 0) {
IP = httpRequest.getHeader("Proxy-Client-IP");
}
if (IP == null || IP.length() == 0) {
IP = httpRequest.getHeader("WL-Proxy-Client-IP");
}
if (IP == null || IP.length() == 0) {
IP = httpRequest.getRemoteAddr();
}
// 得到訪問者所在網段
String subIP = IP.substring(0, IP.lastIndexOf("."));
System.out.println("真實的IP地址:" + IP+"網段是:"+subIP);