首页 > 新闻系统 > 编程天地 > 文章正文

C++查詢wry.dat中的IP地址信息代码

2008-03-24 15:56:54 来源:中国自学编程网 作者:佚名 点击:
直接上代碼(哪一位有不明白的地方,請留言):

    if(searchIpNum<0xFF)...{
        return -1;
    }
    ifstream fs;
    fs.open(dat, ios::binary | ios::in, 0);
    if((!fs.is_open()) || (!fs.good())) ...{
        return -2;
    }
#if defined _DEBUG_
    cout<<" searchIpNum="<<searchIpNum<<", exeOffset="<<exeOffset<<endl;
#endif
    fs.seekg(exeOffset, ios_base::beg);
    ipBeginPos=read4Bit(fs);
#if defined _DEBUG_
    cout<<" ipBeginPos="<<ipBeginPos<<endl;
#endif
    ipEndPos=read4Bit(fs);
#if defined _DEBUG_
    cout<<" ipEndPos="<<ipEndPos<<endl;
#endif
    totalNum = (ipEndPos - ipBeginPos) / 7;
#if defined _DEBUG_
    cout<<" totalNum="<<totalNum<<endl;
#endif
    if(totalNum<1)...{
        return -3;
    }
    beginNum = 0;
    endNum   = totalNum;
    while( 1 ) ...{ //IP的索引是有順序的,按照個數來二分查找.
        midNum= beginNum+(DWORD)((endNum - beginNum)/2);
        pos = ipBeginPos+midNum*7;
        fs.seekg(exeOffset+pos, ios_base::beg);
#if defined _DEBUG_
        cout<<"times="<<++times<<", beginNum="<<beginNum<<", endNum="<<endNum  
 
        <<", midNum="<<midNum<<", exeOffset+pos="<<exeOffset+pos
            <<endl;
#endif
        ip1Num=read4Bit(fs);
        if( ip1Num<1 ) ...{
            fs.close(); cout<<"[1]while(){...}"<<endl;
            return -2;
        }
#if defined _DEBUG_
        //printIpNum(ip1Num);
#endif
        fs.seekg(3, ios_base::cur);
        ip2Num=read4Bit(fs);
        if( ip2Num<1 ) ...{
            fs.close(); cout<<"[3]while(){...}"<<endl;
            return -2;
        }
#if defined _DEBUG_
        //printIpNum(ip2Num);
#endif
9 7 3 1 2 3 4 5 4 8 :

精彩推荐
焦点大图推荐
本类热门文章

论坛美图

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203