读书人

获取ip地址并展示其来源城市地区

发布时间: 2012-11-04 10:42:42 作者: rapoo

获取ip地址并显示其来源城市地区

1. 准备工作

? ? (1)下载最新版本的IP数据库QQWry.Dat

? ? (2)下载IPLocation.dll ? 点我下载

?

2.?在项目中添加引用,引用IPLocation.dll

? ? 添加引用:using IPLocation.IPLocation;
3. 利用其函数获取其地址? ? 关键函数介绍:? ? IPLocate(Byval StrConn as string,Byval StrIp as string)? ? 其中:StrConn 为数据库连接字符串,如:Server.MapPath("QQWry.Dat")? ? ? ? ? ? ? StrIP ? ? 为查询IP? ? ? ? ? ? ? 返回值是字符串型,是IP的地址
4. 示例:??????? 将QQWry.Dat放在网站的根目录下??????? string conn, ipstr, addstr;
??????? conn = Server.MapPath("QQWry.Dat");
??????? ipstr = HttpContext.Current.Request.UserHostAddress;//获取客户端ip地址
??????? addstr = IPLocation.IPLocation.IPLocate(conn, ipstr);
??????? Label1.Text = "IP:" + ipstr + "<br>地址:" + addstr;
注意事项:要定期的更新最新版本的QQWry.Dat(可以下载纯真IP数据库查询器来得到这个文件

?

读书人网 >编程

热点推荐