IPQuery 库使用说明

因之前的文章《IP地址库解析》上传文件错误,导致许多网友运行时出现错误,在此向各位道歉了。

在此奉上使用说明:

============================================
使用说明
============================================
1、下载 qqwry.dat
http://www.onlinedown.net/soft/19051.htm

2、解压文件,放到网站的bin目录下。
形成如下结构:

IPQuery 库使用说明



3、浏览首页: Default.aspx 即可

============================================
IPQUERY.DLL 使用说明
============================================
1、在网站根目录下初始化IP数据库文件

protected void Application_Start(object sender, EventArgs e)

{

	// 这里初始化查询引擎,设置 qqwry.dat 的网站根目录

	string ipData = Server.MapPath(@"~\bin\qqwry.dat");

	IPQuery.Facade.SingleQuery.Instance.SetDataFilePath(ipData);

}

  

2、查询ip地址

/// <summary>

/// 点击查询按钮

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void btnQuery_Click(object sender, EventArgs e)

{

	string ip = this.TextBox1.Text;

	if (string.IsNullOrEmpty(ip))

	{

		this.Page.Response.Write("大哥,好歹也给个地址啊!");

		return;

	}

	this.Page.Response.Write(this.Output(SingleQuery.Instance.Find(ip)));

}

	

/// <summary>

/// 输出IP地址记录

/// </summary>

/// <param name="ipRecord"></param>

/// <returns></returns>

private string Output(IPAddressRecord ipRecord)

{

	if (null != ipRecord)

	{

		return string.Format("{0} - {1} {2} {3}", AddressConvert.UInt32ToIpV4String(ipRecord.IPStart), AddressConvert.UInt32ToIpV4String(ipRecord.IPEnd), ipRecord.Country, ipRecord.Area);

	}

	return string.Empty;

}

  

============================================
××××××××××××××××××××××××××××××××××××××××××××
作者:孤剑
http://www.cnblogs.com/alonesword/
http://blog.csdn.net/alonesword/

你可能感兴趣的:(query)