xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 3.44MB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-10-29
  • 語言: C/C++
  • 標(biāo)簽: c/c++??

資源簡介

封裝在一個類里的可以直接運(yùn)行的ip數(shù)據(jù)庫查詢,可以直接在自己的程序中調(diào)用該類,并且?guī)в凶钚碌?0110920QQwry.dat

資源截圖

代碼片段和文件信息

#include?“IPSearch.h“

IPSearch::IPSearch()
{
this->data?=?0;??//指向純真IP數(shù)據(jù)庫的指針
}

IPSearch::~IPSearch()
{
}

//?功能:將純真IP數(shù)據(jù)庫中的所有數(shù)據(jù)讀入全局?jǐn)?shù)組data
//?參數(shù):file?文件字符串
//?返回值:?0?成功?

int?IPSearch::init(byte*?file)
{
ulong?fileSize;????//文件長度
FILE*?fp;

fp?=?fopen((char*)file“rb“);
if(fp?==?NULL)
return?1;

//獲取文件長度
fseek(fp???0???SEEK_END);??
fileSize???=???ftell(fp);??

//將純真IP數(shù)據(jù)庫中的所有數(shù)據(jù)讀入數(shù)組
data=(byte*)malloc(fileSize*?sizeof(byte));
fseek(fp0SEEK_SET);
fread(data1fileSizefp);
if(data?==?NULL)
return?2;
fclose(fp);
fp=NULL;

//讀取IP數(shù)據(jù)庫文件頭
dbheader.firstStartIpOffset=getInt32(&data[0]4);?
dbheader.lastStartIpOffset=getInt32(&data[4]4);?
//printf(“%ld???%ld??\n“dbheader.firstStartIpOffsetdbheader.lastStartIpOffset);

return?0;
}


//?功能:查詢ipStr
IPLocation??IPSearch::queryIp(byte*?ipStr)
{
ulong?ip;
ulong?offset;

if(init((byte*)“QQWry.Dat“)==1)
{
printf(“QQWry.Dat?初始化失??!\n“);
}

ip=IpToLong(ipStr);

offset=getOffsetOfIp(ip);

//printf(“ip:%u?offset:?%u“ipoffset);

return??getIPLocation(offset);
}

//功能:?二分法獲得IP記錄偏移量
//參數(shù):ip?待查詢ip
//返回值:相對于文件頭的偏移量?(0??失敗)
ulong?IPSearch::getOffsetOfIp(ulong?ip)
{
ulong?low=0;
ulong?high=(dbheader.lastStartIpOffset-dbheader.firstStartIpOffset)/7;?
ulong?endIpOff;
ulong?mid;

while(low {
mid=(low+high)/2;
if(ip high=mid;
else
low=mid;
}

//printf(“\nlow:%ld?\n“l(fā)ow);
if(ip>=getIpFromIndex(low&endIpOff)&&ip<=getIpFromRecord(endIpOff))
{
return?endIpOff;
}

return??0L;
}


//?功能:從索引區(qū)獲得IP地址
//?參數(shù):left?索引
//?返回值:起始Ip地址
//????????endIpOff?該索引所對應(yīng)的結(jié)束Ip偏移量

ulong?IPSearch::getIpFromIndex(ulong?leftulong*?addr)
{
ulong?leftOffset?=?dbheader.firstStartIpOffset?+?(left?*?7L);
*addr=getInt32(&data[leftOffset+4]3);
return?getInt32(&data[leftOffset]4);
}


//?功能:從記錄區(qū)獲得IP地址
ulong?IPSearch::getIpFromRecord(ulong?endIpOff)
{
return?getInt32(&data[endIpOff]4);
}

//?功能:將字符數(shù)組轉(zhuǎn)成一個整數(shù)
ulong?IPSearch::getInt32(byte*?bufint?num)
{
ulong?ret=0;
int?i;

for(i=0;i {
ret+=(buf[i]<<(8*i));
}
return?ret?;
}

//將ip從字符串形式轉(zhuǎn)化為一個長整數(shù)
ulong?IPSearch::IpToLong(byte*?ipStr)
{
byte*?p=ipStr;
byte?ch;
int?i=0;
int?shift=24;
ulong?ret=0temp;

for(i=0;i<4;i++)
{
temp=0;
while((ch=*p++)!=‘.‘?&&?ch)
temp=temp*10+(ch?-‘0‘);
ret+=(temp< shift-=8;
}
if(i!=4)
return?-1;
return?ret;
}


//?功能:給定一個ip國家地區(qū)記錄的偏移,返回一個IPLocation結(jié)構(gòu)
//?參數(shù):?offset?國家記錄的起始偏移
//?返回值:IPLocation對象

IPLocation?IPSearch::getIPLocation(ulong?offset)
{
byte?flag_char;

//?跳過4字節(jié)ip讀取隨后字節(jié)判斷是否為標(biāo)志字節(jié)
flag_char=data[offset+4];

if(flag_char?==?REDIRECT_MODE_1)?{
//?讀取國家偏移(3個字節(jié))
ulong?countryOffset=getInt32(&data[offset+5]3);

//?再檢查一次標(biāo)志字節(jié),因?yàn)檫@個時候這個地方仍然可能是個重定向
flag_char=data[countryOffset];
if(flag_char?==?REDIRECT_MODE_2)?{
//?讀取國家偏移
int?temp;
temp=getInt3

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????36352??2011-10-10?14:33??ip_c_class\Debug\ip_c_class.exe

?????文件?????352768??2011-10-10?14:33??ip_c_class\Debug\ip_c_class.ilk

?????文件?????584704??2011-10-10?14:33??ip_c_class\Debug\ip_c_class.pdb

?????文件???????6914??2011-10-10?14:33??ip_c_class\ip_c_class\Debug\BuildLog.htm

?????文件??????17571??2011-10-10?14:33??ip_c_class\ip_c_class\Debug\IPSearch.obj

?????文件????????663??2011-10-10?13:24??ip_c_class\ip_c_class\Debug\ip_c_class.exe.embed.manifest

?????文件????????728??2011-10-10?13:24??ip_c_class\ip_c_class\Debug\ip_c_class.exe.embed.manifest.res

?????文件????????621??2011-10-10?14:33??ip_c_class\ip_c_class\Debug\ip_c_class.exe.intermediate.manifest

?????文件?????????67??2011-10-10?14:33??ip_c_class\ip_c_class\Debug\mt.dep

?????文件??????25513??2011-10-10?14:33??ip_c_class\ip_c_class\Debug\test.obj

?????文件?????191488??2011-10-10?14:33??ip_c_class\ip_c_class\Debug\vc90.idb

?????文件?????217088??2011-10-10?14:33??ip_c_class\ip_c_class\Debug\vc90.pdb

?????文件???????4726??2011-10-10?14:28??ip_c_class\ip_c_class\IPSearch.cpp

?????文件???????2037??2011-10-10?14:30??ip_c_class\ip_c_class\IPSearch.h

?????文件???????4048??2011-10-10?11:15??ip_c_class\ip_c_class\ip_c_class.vcproj

?????文件???????1427??2011-10-10?14:34??ip_c_class\ip_c_class\ip_c_class.vcproj.PC-201108081419.Administrator.user

?????文件????9151777??2011-09-20?19:28??ip_c_class\ip_c_class\QQWry.Dat

?????文件????????404??2011-10-10?14:32??ip_c_class\ip_c_class\test.cpp

?????文件????1567744??2011-10-10?14:34??ip_c_class\ip_c_class.ncb

?????文件????????896??2011-10-10?11:09??ip_c_class\ip_c_class.sln

????..A..H.?????14336??2011-10-10?14:34??ip_c_class\ip_c_class.suo

?????目錄??????????0??2011-10-10?14:33??ip_c_class\ip_c_class\Debug

?????目錄??????????0??2011-10-10?14:30??ip_c_class\Debug

?????目錄??????????0??2011-10-10?14:32??ip_c_class\ip_c_class

?????目錄??????????0??2011-10-10?11:54??ip_c_class

-----------?---------??----------?-----??----

?????????????12181872????????????????????25


評論

共有 條評論