62,041
社区成员
发帖
与我相关
我的任务
分享
#region 获取结束IP
private long GetEndIp()
{
//objfs.Seek(endIpOff,SeekOrigin.Begin);
objfs.Position = endIpOff;
byte[] buff = new Byte[5];
objfs.Read(buff, 0, 5);
this.endIp = Convert.ToInt64(buff[0]) + Convert.ToInt64(buff[1]) * 256 + Convert.ToInt64(buff[2]) * 256 * 256 + Convert.ToInt64(buff[3]) * 256 * 256 * 256;
this.countryFlag = buff[4];
return this.endIp;
}
#endregion
#region 获取国家/区域偏移量
private string GetCountry()
{
switch (this.countryFlag)
{
case 1:
case 2:
this.country = GetFlagStr(this.endIpOff + 4);
this.local = (1 == this.countryFlag) ? " " : this.GetFlagStr(this.endIpOff + 8);
break;
default:
this.country = this.GetFlagStr(this.endIpOff + 4);
this.local = this.GetFlagStr(objfs.Position);
break;
}
return " ";
}
#endregion
#region 获取国家/区域字符串
private string GetFlagStr(long offSet)
{
int flag = 0;
byte[] buff = new Byte[3];
while (1 == 1)
{
//objfs.Seek(offSet,SeekOrigin.Begin);
objfs.Position = offSet;
flag = objfs.ReadByte();
if (flag == 1 || flag == 2)
{
objfs.Read(buff, 0, 3);
if (flag == 2)
{
this.countryFlag = 2;
this.endIpOff = offSet - 4;
}
offSet = Convert.ToInt64(buff[0].ToString()) + Convert.ToInt64(buff[1].ToString()) * 256 + Convert.ToInt64(buff[2].ToString()) * 256 * 256;
}
else
{
break;
}
}
if (offSet < 12)
return " ";
objfs.Position = offSet;
return GetStr();
}
#endregion
#region GetStr
private string GetStr()
{
byte lowC = 0;
byte upC = 0;
string str = "";
byte[] buff = new byte[2];
while (1 == 1)
{
lowC = (Byte)objfs.ReadByte();
if (lowC == 0)
break;
if (lowC > 127)
{
upC = (byte)objfs.ReadByte();
buff[0] = lowC;
buff[1] = upC;
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("GB2312");
str += enc.GetString(buff);
}
else
{
str += (char)lowC;
}
}
return str;
}
#endregion
#region 获取IP的地理地址
/// <summary>
/// 获取IP的地理地址
/// </summary>
/// <returns></returns>
public string IPLocation()
{
this.QQwry();
return this.country + this.local.Replace("CZ88.NET", "");//删除垃圾信息
}
/// <summary>
/// 获取IP的地理地址
/// </summary>
/// <param name="dataPath"></param>
/// <param name="ip"></param>
/// <returns></returns>
public string IPLocation(string dataPath, string strip)
{
this.dataPath = dataPath;
this.ip = strip;
this.QQwry();
return this.country + this.local.Replace("CZ88.NET", "");//删除垃圾信息
}
/// <summary>
/// 获取IP的地理地址,专门給统计系统用的
/// </summary>
/// <param name="strip"></param>
/// <returns></returns>
public string IPCountry(string strip)
{
this.ip = strip;
this.QQwry();
return this.country;
}
public string IPLocal(string strip)
{
this.ip = strip;
this.QQwry();
if (this.local == null)
return "";
return this.local.Replace("CZ88.NET", "");//删除垃圾信息
}