예제 #1
0
        /// <summary>
        /// 搜索IP地址搜索
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public IpLocation SearchIpLocation(string ip)
        {
            //将字符IP转换为字节
            string[] ipSp = ip.Split('.');
            if (ipSp.Length != 4)
            {
                throw new ArgumentOutOfRangeException("不是合法的IP地址!");
            }
            byte[] IP = new byte[4];
            for (int i = 0; i < IP.Length; i++)
            {
                IP[i] = (byte)(Int32.Parse(ipSp[i]) & 0xFF);
            }
            IpLocation local  = null;
            long       offset = LocateIp(IP);

            if (offset != -1)
            {
                local = GetIpLocation(offset);
            }
            if (local == null)
            {
                local         = new IpLocation();
                local.Area    = UnArea;
                local.Country = UnCountry;
            }
            return(local);
        }
예제 #2
0
        /// <summary>
        /// 获取版本
        /// </summary>
        /// <returns></returns>
        public IpLocation GetCopy()
        {
            IpLocation ret = new IpLocation();

            ret.Country = Country;
            ret.Area    = Area;
            return(ret);
        }
예제 #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="ipfile">IP数据库文件绝对路径</param>
 public QqWry(string ipfile)
 {
     _buf = new byte[100];
     _b3  = new byte[3];
     _b4  = new byte[4];
     try
     {
         _ipFile = new FileStream(ipfile, FileMode.Open, FileAccess.Read, FileShare.Read);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     _ipBegin = ReadLong4(0);
     _ipEnd   = ReadLong4(4);
     _loc     = new IpLocation();
 }