Пример #1
0
 protected IPQuery.CZ_INDEX_INFO IndexInfoAtPos(uint Index_Pos)
 {
     IPQuery.CZ_INDEX_INFO cz_index_info = new IPQuery.CZ_INDEX_INFO();
     this.FileStrm.Seek(( long )(this.Index_Set + (7 * Index_Pos)), SeekOrigin.Begin);
     cz_index_info.IpSet  = this.GetUInt32();
     cz_index_info.Offset = this.GetOffset();
     this.FileStrm.Seek(( long )cz_index_info.Offset, SeekOrigin.Begin);
     cz_index_info.IpEnd = this.GetUInt32();
     return(cz_index_info);
 }
Пример #2
0
            /// <summary>
            /// 获取IP地址归属地
            /// </summary>
            /// <param name="IPValue">要查找的IP地址</param>
            /// <returns></returns>
            public string GetAddressWithIP(string IPValue)
            {
                if (!this.bFilePathInitialized)
                {
                    return("");
                }
                this.Initialize();
                uint num = this.IPToUInt32(IPValue);

                while (true)
                {
                    //首先初始化本轮查找的区间

                    //区间头
                    this.Search_Set = this.IndexInfoAtPos(this.Search_Index_Set);
                    //区间尾
                    this.Search_End = this.IndexInfoAtPos(this.Search_Index_End);

                    if ((num >= this.Search_Set.IpSet) && (num <= this.Search_Set.IpEnd))
                    {
                        return(this.ReadAddressInfoAtOffset(this.Search_Set.Offset));
                    }
                    if ((num >= this.Search_End.IpSet) && (num <= this.Search_End.IpEnd))
                    {
                        return(this.ReadAddressInfoAtOffset(this.Search_End.Offset));
                    }
                    this.Search_Mid = this.IndexInfoAtPos((this.Search_Index_End + this.Search_Index_Set) / 2);
                    if ((num >= this.Search_Mid.IpSet) && (num <= this.Search_Mid.IpEnd))
                    {
                        return(this.ReadAddressInfoAtOffset(this.Search_Mid.Offset));
                    }
                    if (num < this.Search_Mid.IpSet)
                    {
                        this.Search_Index_End = (this.Search_Index_End + this.Search_Index_Set) / 2;
                    }
                    else
                    {
                        this.Search_Index_Set = (this.Search_Index_End + this.Search_Index_Set) / 2;
                    }
                }
            }