日期:2011-05-12 浏览次数:20420 次
下载CS文件:http://www.cnblogs.com/Files/rexsp/IPExport.rar
/**//******************************************************************
** File Name:IPExport.cs
** Copyright (c) 2004-2005 PPTech Studio(PPTech.Net)
** Creater:Rexsp(MSN:yubo@x263.net)
** Create Date:2004-12-29 20:10:28
** Modifier:
** Modify Date:
** Description:to export the ip location from qqwry.dat
** Version: IPExport 1.0.0
******************************************************************/
using System;
using System.Collections;
using System.Data;
using System.IO;
namespace PPTech.ESP.Component
{
/**//// <summary>
/// ExportData 的摘要说明。
/// </summary>
public class IPExport
{
私有成员#region 私有成员
private string country;
private string local;
private FileStream objfs = null;
private long startIp=0;
private long endIp=0;
private int countryFlag=0;
private long endIpOff=0;
#endregion
构造函数#region 构造函数
public IPExport()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#endregion
导出数据#region 导出数据
public void SaveToText(string toFilePath,string fromFilePath)
{
objfs = new FileStream(fromFilePath, FileMode.Open, FileAccess.Read);
objfs.Position=0;
byte[] buff1 = new Byte[8] ;
objfs.Read(buff1,0,8);
int firstStartIp=buff1[0]+buff1[1]*256+buff1[2]*256*256+buff1[3]*256*256*256;
int lastStartIp=buff1[4]*1+buff1[5]*256+buff1[6]*256*256+buff1[7]*256*256*256;
long recordCount=Convert.ToInt64((lastStartIp-firstStartIp)/7.0);
if(recordCount<=1)
{
country="FileDataError";
objfs.Close();
}
long rangE=recordCount;
StreamWriter writer=File.AppendText(toFilePath);