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

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

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

        if( (ip1Num<=searchIpNum) && (searchIpNum<=ip2Num) )...{
            fs.seekg(exeOffset+pos, ios_base::beg);
            ip1Num=read4Bit(fs);
#if defined _DEBUG_
            cout<<"  Last position:"<<endl<<endl;
            printIpNum(ip1Num);
            cout<<"pos="<<pos<<"   ";
#endif
            pos=read3Bit(fs);
#if defined _DEBUG_
            cout<<"pos="<<pos<<endl;
#endif
            fs.seekg(exeOffset+pos, ios_base::beg);
         ip2Num=read4Bit(fs);
#if defined _DEBUG_
            printIpNum(ip2Num);
#endif
            break;
        }else if(ip1Num>searchIpNum)...{
            endNum = midNum;
        }else if(ip2Num<searchIpNum)...{
            beginNum = midNum;
        }
    }
#if defined _DEBUG_
    cout<<endl<<"Found position:"<<fs.tellg()<<endl;
#endif
    ipAddr=new char[512];
    memset(ipAddr, 0, 512);
    iRead = readString(fs, exeOffset, ipAddr);
    if(iRead>0)...{
        cout<<ipAddr<<"  ";
    }
    memset(ipAddr, 0, 512);
    iRead = readString(fs, exeOffset, ipAddr);
    if(iRead>0)...{
        cout<<ipAddr;
    }
    delete[]ipAddr;
    fs.close();
    return 0;
}
long read4Bit(ifstream& f)...{
    long t; char c[4];
    t=0;
    f.read((char*)&t, 4);
    return t;
}
long read3Bit(ifstream& f)...{
    long t;
    f.read((char*)&t, 3);
    return t;
}
int readString(ifstream& f, long exeOffset, char * str)...{
    char ipFlag; long ipSeek, tmpSeek;
    int ret;
    ipFlag=f.get();
    if(ipFlag==0x1) ...{ // 重定向模式1: 城市信息隨國家信息定向
        ipSeek=read3Bit(f);
        f.seekg(exeOffset+ipSeek, ios_base::beg);
9 7 3 1 2 3 4 5 4 8 :

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

论坛美图

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

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