`

根据IP地址获取所在地

    博客分类:
  • java
阅读更多

主要Test.java

public class Test {
	public static void main(String[] args) {
		String address = "";
		String ipCityName = "";
		try {
			IPSeeker seeker = IPSeeker.getInstance(ServletActionContext
					.getServletContext());
			HttpServletRequest request = ServletActionContext.getRequest();
			String ip = GroupUtil.getIpAddr(request);
			// String ip = "125.92.141.237";
			address = seeker.getAddress(ip);
			System.out.println("根据IP自动获得城市区域:" + address);
			int beginIndex = address.indexOf("省");
			int endIndex = address.indexOf("市");
			ipCityName = address.substring(beginIndex + 1, endIndex);
			// String city =
			// groupManagerService.getCityInfoByConditon(GroupUtil.getMap(
			// "cityName", ipCityName));
		} catch (Exception e) {
			System.out.println("访问出现错误,出现错误的IP:++++++++++" + address
					+ " 出现错误的城市:++++++++++++++++++" + ipCityName);
		}
	}
}

 其它代码请见下载包

分享到:
评论
3 楼 yu_long 2013-04-07  
seeker.getCountry(ip);  
解析出来的国家不对,打印出来的却是 地名
2 楼 wangyong31893189 2012-08-31  
thtio520 写道
不行  没用

报什么错呢?
1 楼 thtio520 2012-08-09  
不行  没用

相关推荐

Global site tag (gtag.js) - Google Analytics