java获取客户IP并判断客户所在的地区!
java获取客户IP并判断客户所在的地区!
public static String getIpAddr(HttpServletRequest request) {
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;
}
我是这样做的,这段代码如果我在地址栏中输入:192.168.0.xx/:8080得到的就是这个地址,如果输入:localhost:8080得到的就是127.0.0.1,这是在局域网上,没有放到公网上试,不知道这段代码是否可行,还有其它方法获取IP吗?并根据判断客户所在地区!
急!!!!!!!!!!!!!!谢谢!!!!!!!!!!!!!!!1
------解决方案--------------------要判断ip所在地区得有个IP库..
关于读取qq纯真IP库..在网上有现成代码..
------解决方案--------------------参考这个 http://zhidao.baidu.com/question/19460354.html?fr=qrl3
------解决方案--------------------參考一下這個網站的例子,好像不錯
http://www.pushad.com/Info/13275.Html