当前位置:编程学习 > C#/ASP.NET >>

请问我想做个根据访问者ip范围,显示属于该范围的Ip的在线情况

请问我想做个根据访问者ip范围,显示属于该范围的Ip的在线情况,正在访问页面,和该范围的总点击量。求解。 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 1.这个你需要有个IP库,网上有的也可以下。
2.用户登录必须做一个记录日志,用户在线情况可以通过application和lock来处理。
3.如何通过ip段来确定人呢,这个需要把ip地址转成整数然后到ip库里面去查找。可以通过下面的方法把ip和整数进行互转:
/// <summary>
        /// 将IP地址转为整数形式
        /// </summary>
        /// <returns>整数</returns>
        public static long IP2Long(IPAddress ip)
        {
            int x = 3;
            long o = 0;
            foreach (byte f in ip.GetAddressBytes())
            {
                o += (long)f << 8 * x--;
            }
            return o;
        }
        /// <summary>
        /// 将整数转为IP地址
        /// </summary>
        /// <returns>IP地址</returns>
        public static IPAddress Long2IP(long l)
        {
            byte[] b = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                b[3 - i] = (byte)(l >> 8 * i & 255);
            }
            return new IPAddress(b);
        }

另外再贴一个获取ip的
/// <summary>
        /// 获得客户端IP
        /// </summary>
        public static string ClientIP
        {
            get
            {
                string ip;
                string[] temp;
                bool isErr = false;
                if (HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null)
                    ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
                else
                    ip = HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString();
                if (ip.Length > 15)
                    isErr = true;
                else
                {
                    temp = ip.Split('.');
                    if (temp.Length == 4)
                    {
                        for (int i = 0; i < temp.Length; i++)
                        {
                            if (temp[i].Length > 3) isErr = true;
                        }
                    }
                    else
                        isErr = true;
                }

                if (isErr)
                    return "1.1.1.1";
                else
                    return ip;
            }
        }
--------------------编程问答-------------------- 获取用户ip地址之后,可以用webservice获取其所在地,然后update 数据库表
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,