国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

導出QQWry.Dat中IP地址到文件[C#]

2024-07-21 02:27:15
字體:
來源:轉載
供稿:網友
,歡迎訪問網頁設計愛好者web開發。

下載cs文件:http://www.cnblogs.com/files/rexsp/ipexport.rar
/**//******************************************************************
** file name:ipexport.cs
** copyright (c) 2004-2005 pptech studio(pptech.net)
** creater:rexsp(msn:[email protected])
** 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);
            for(int i=0;i<=recordcount;i++)
            {
                long offset = firststartip+i*7;
                objfs.position=offset;
            
                byte [] buff = new byte[7];
                objfs.read(buff,0,7);
 
                endipoff=convert.toint64(buff[4].tostring())+convert.toint64(buff[5].tostring())*256+convert.toint64(buff[6].tostring())*256*256;
                startip=convert.toint64(buff[0].tostring())+convert.toint64(buff[1].tostring())*256+convert.toint64(buff[2].tostring())*256*256+convert.toint64(buff[3].tostring())*256*256*256;
                
                objfs.position=endipoff;
                byte [] buff3 = new byte[5];
                objfs.read(buff3,0,5);
                this.endip=convert.toint64(buff3[0].tostring())+convert.toint64(buff3[1].tostring())*256+convert.toint64(buff3[2].tostring())*256*256+convert.toint64(buff3[3].tostring())*256*256*256;
                this.countryflag=buff3[4];
                string showip=this.inttoip(startip);
                this.getcountry();
                writer.writeline(showip+" "+this.country+this.local);
            }
            writer.close();
 
        }
        #endregion
 
        int轉換成ip#region int轉換成ip
        private string  inttoip(long ip_int)
        {
            long seg1=(ip_int&0xff000000)>>24;
            if(seg1<0)
                seg1+=0x100;
            long seg2=(ip_int&0x00ff0000)>>16;
            if(seg2<0)
                seg2+=0x100;
            long seg3=(ip_int&0x0000ff00)>>8;
            if(seg3<0)
                seg3+=0x100;
            long seg4=(ip_int&0x000000ff);
            if(seg4<0)
                seg4+=0x100;
            string ip=seg1.tostring()+"."+seg2.tostring()+"."+seg3.tostring()+"."+seg4.tostring();
 
            return ip;
        }
        #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
 
        getstr#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
    }

 


調用方式:


            測試導出ip地址庫#region 測試導出ip地址庫
            ipexport exp = new ipexport();
            string tofile = @"d:/work/pptechstudio/ip.txt";
            string [email protected]"e:/個人資料/imtools/qqwryupdate/qqwry.dat";
            exp.savetotext(tofile,fromfile);
            #endregion

 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绵阳市| 盱眙县| 修武县| 教育| 周至县| 衡阳县| 红安县| 同心县| 云林县| 河间市| 敦化市| 西宁市| 湾仔区| 甘肃省| 凤阳县| 逊克县| 措勤县| 仪征市| 宜都市| 黄平县| 麦盖提县| 宁武县| 新干县| 沙洋县| 中方县| 东台市| 陵水| 芒康县| 沐川县| 泸溪县| 彭泽县| 安达市| 白河县| 平度市| 贞丰县| 西丰县| 沂水县| 道孚县| 上高县| 辉南县| 佛教|