using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Stat.web.MyAJAX
{
    /// <summary>
    /// HdfGetIpinfo 的摘要说明
    /// </summary>
    public class HdfGetIpinfo : IHttpHandler
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Expires = 0;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.ContentType = "text/plain";
            // context.Response.Write("Hello World");

            string ip = string.Empty;

            if (HttpContext.Current.Request.QueryString["ip"] != null)
            {
                ip = HttpContext.Current.Request.QueryString["ip"].ToString();
                context.Response.Write(GetIpinfo(ip));
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public string GetIpinfo(string ip)
        {
            DataTable dt = BLL.IP.Get(ip);
            if (dt != null && dt.Rows.Count > 0)
            {
                return dt.Rows[0]["IPinfo"].ToString();
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}