当前位置: 代码迷 >> JavaScript >> java jsp 获取 天真ip地址库(ip获取城市)
  详细解决方案

java jsp 获取 天真ip地址库(ip获取城市)

热度:533   发布时间:2012-09-13 09:51:53.0
java jsp 获取 纯真ip地址库(ip获取城市)

?

介绍通过IP地址查找ip具体的城市和运营商!

通过QQIP地址库:QQWry.Dat编写
以下只贴出少量代码,请各位直接到本人的网盘下载完整版(代码+最新QQWry.Dat),项目可直接运行!
QQWry.Dat大小为8.79M,项目大小仅390k,直接运行IPTest.java类即可!
此代码可用于各种java项目和jsp、j2ee项目
注意:QQWry.Dat只需文件放在对应的目录下即可。

网盘下载地址:http://115.com/file/dplk9jqn#

  1. public?class?IPSeeker?{??
  2. ????//纯真IP数据库名??
  3. ????private?String?IP_FILE="QQWry.Dat";??
  4. ????//保存的文件夹??
  5. ????private?String?INSTALL_DIR="f:/qqwry";??
  6. ??????
  7. ??????
  8. ????//?一些固定常量,比如记录长度等等??
  9. ????private?static?final?int?IP_RECORD_LENGTH?=?7;??
  10. ????private?static?final?byte?REDIRECT_MODE_1?=?0x01;??
  11. ????private?static?final?byte?REDIRECT_MODE_2?=?0x02;??
  12. ??????
  13. ????//?用来做为cache,查询一个ip时首先查看cache,以减少不必要的重复查找??
  14. ????private?Map<String,?IPLocation>?ipCache;??
  15. ????//?随机文件访问类??
  16. ????private?RandomAccessFile?ipFile;??
  17. ????//?内存映射文件??
  18. ????private?MappedByteBuffer?mbb;??
  19. ????//?起始地区的开始和结束的绝对偏移??
  20. ????private?long?ipBegin,?ipEnd;??
  21. ????//?为提高效率而采用的临时变量??
  22. ????private?IPLocation?loc;??
  23. ????private?byte[]?buf;??
  24. ????private?byte[]?b4;??
  25. ????private?byte[]?b3;??
  26. ??????
  27. ????public?IPSeeker(String?fileName,String?dir)??{??
  28. ????????this.INSTALL_DIR=dir;??
  29. ????????this.IP_FILE=fileName;??
  30. ????????ipCache?=?new?HashMap<String,?IPLocation>();??
  31. ????????loc?=?new?IPLocation();??
  32. ????????buf?=?new?byte[100];??
  33. ????????b4?=?new?byte[4];??
  34. ????????b3?=?new?byte[3];??
  35. ????????try?{??
  36. ????????????ipFile?=?new?RandomAccessFile(IP_FILE,?"r");??
  37. ????????}?catch?(FileNotFoundException?e)?{?
  38. ...........
  39. .............
  40. ................

?

  相关解决方案