country = ReadString();
area = ReadArea();
}
}
else if (Tag == 0x02)
{
//模式0x02,说明国家信息是一个偏移位置
country_Offset = GetOffset();
//先读取地区信息
area = ReadArea();
//读取国家信息
FileStrm.Seek(country_Offset, SeekOrigin.Begin);
country = ReadString();
}
else
{
//这种模式最简单了,直接读取国家和地区就OK了
FileStrm.Seek(-1, SeekOrigin.Current);
country = ReadString();
area = ReadArea();
}
string Address = country + " " + area;
return Address;
}
private UInt32 GetOffset()
{
byte[] TempByte4 = new byte[4];
TempByte4[0] = (byte)FileStrm.ReadByte();
TempByte4[1] = (byte)FileStrm.ReadByte();
TempByte4[2] = (byte)FileStrm.ReadByte();
TempByte4[3] = 0;
return BitConverter.ToUInt32(TempByte4, 0);
}
protected string ReadArea()
{
byte Tag = GetTag();
if (Tag == 0x01 || Tag == 0x02)
{
FileStrm.Seek(GetOffset(), SeekOrigin.Begin);
return ReadString();
}
else
{
FileStrm.Seek(-1, SeekOrigin.Current);
return ReadString();
}
}
protected string ReadString()
{
UInt32 Offset = 0;
byte[] TempByteArray = new byte[256];
TempByteArray[Offset] = (byte)FileStrm.ReadByte();
while (TempByteArray[Offset] != 0x00)
{
Offset += 1;
TempByteArray[Offset] = (byte)FileStrm.ReadByte();
}
return System.Text.Encoding.Default.GetString(TempByteArray).TrimEnd(' ');
}
protected byte GetTag()
{
return (byte)FileStrm.ReadByte();
}
protected CZ_INDEX_INFO IndexInfoAtPos(UInt32 Index_Pos)
{
CZ_INDEX_INFO Index_Info = new CZ_INDEX_INFO();
//根据索引编号计算出在文件中在偏移位置
FileStrm.Seek(Index_Set + 7 * Index_Pos, SeekOrigin.Begin);
Index_Info.IpSet = GetUInt32();
Index_Info.Offset = GetOffset();
FileStrm.Seek(Index_Info.Offset, SeekOrigin.Begin);
Index_Info.IpEnd = GetUInt32();
return Index_Info;
}
/// <summary>
/// 从IP转换为Int32
/// </summary>
/// <param name="IpValue"></param>
/// <returns></returns>
public UInt32 IPToUInt32(string IpValue)
{
string[] IpByte = IpValue.Split('.');
Int32 nUpperBound = IpByte.GetUpperBound(0);
if (nUpperBound != 3)
{
IpByte = new string[4];
for (Int32 i = 1; i <= 3 - nUpperBound; i++)
IpByte[nUpperBound + i] = "0";
}
byte[] TempByte4 = new byte[4];
for (Int32 i = 0; i <= 3; i++)
{
//'如果是.Net 2.0可以支持TryParse。
//'If Not (Byte.TryParse(IpByte(i), TempByte4(3 - i))) Then
//' TempByte4(3 - i) = &H0
//'End If
if (IsNumeric(IpByte[i]))
TempByte4[3 - i] = (byte)(Convert.ToInt32(IpByte[i]) & 0xff);
}
return BitConverter.ToUInt32(TempByte4, 0);
}
/// <summary>
/// 判断是否为数字
/// </summary>
/// <param name="str">待判断字符串</param>








