获得IP地址内容
2015-12-20 20:35:15 访问(1646) 赞(0) 踩(0)
/// <summary>
///
/// </summary>
/// <param name="ip"></param>
/// <param name="xdbHelper"></param>
/// <returns></returns>
protected string GetIpAddress(string ip,DBHelper xdbHelper)
{
string theResult = "未知";
bool bIsCreate = true;
string dbConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Request.PhysicalApplicationPath + "App_Data\\ip\\IPaddress.mdb;Persist Security Info=True;";
if (xdbHelper == null)
{
xdbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper
(
dbConn,
SlowX.DAL.Enums.DataBaseHelper.EmDataBaseHelper.Access,
1
);
}
else
{
// 没有打开链接//
bIsCreate = xdbHelper.IsNotOpen();
}
try
{
if (bIsCreate)
xdbHelper.OpenDBHelper();
string uIp = IpToULong(ip).ToString();
string sql = "select country,city from BBSGOOD_IP where ip1 <= " + uIp + " and ip2 >= " + uIp;
DataSet ds= xdbHelper.ExecuteDataSet(sql);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
theResult = ds.Tables[0].Rows[0]["country"] + "." + ds.Tables[0].Rows[0]["city"];
}
if (bIsCreate)
xdbHelper.EndDBHelper();
}
catch (Exception err)
{
if (bIsCreate)
xdbHelper.TranDBHelper();
throw err;
}
finally
{
if (bIsCreate)
xdbHelper.FinallyDBHelper();
}
return theResult;
}
标签:
获得IP地址内容 


上一条:
下一条:
相关评论
发表评论