📄 qqwry.c
字号:
起始IP为索引部分的前4位16进制
结束IP在IP信息部分的前4位16进制中,靠索引部分指定的偏移量找寻*/
start_ip=getValue(fp,i,4);
end_ip=getValue(fp,getValue(fp,i+4,3),4);
/*导出IP信息,格式是
起始IP\t结束IP\t国家位置\t地域位置\n*/
fprintf(out,"%d.%d.%d.%d",(start_ip&0xFF000000)>>0x18,(start_ip&0x00FF0000)>>0x10,(start_ip&0x0000FF00)>>0x8,start_ip&0x000000FF);
fprintf(out,"\t");
fprintf(out,"%d.%d.%d.%d",(end_ip&0xFF000000)>>0x18,(end_ip&0x00FF0000)>>0x10,(end_ip&0x0000FF00)>>0x8,end_ip&0x000000FF);
getAddress(fp,getValue(fp,i+4,3),&country,&location);
fprintf(out,"\t%s\t%s\n",country,location);
count++;
}
/*返回导出总条数*/
return count;
};
/*判断一个字符是否为数字字符,
如果是,返回0
如果不是,返回1*/
int beNumber(char c)
{
if(c>='0'&&c<='9')
return 0;
else
return 1;
};
/*函数的参数是一个存储着IP地址的字符串首地址
返回该IP的16进制代码
如果输入的IP地址有错误,函数将返回0*/
unsigned long getIP(char *ip_addr)
{
unsigned long ip=0;
int i,j=0;
/*依次读取字符串中的各个字符*/
for(i=0;i<strlen(ip_addr);i++)
{
/*如果是IP地址间隔的‘.’符号
把当前读取到的IP字段的值,存入ip变量中
(注意,ip为叠加时,乘以16进制的0x100)
并清除临时变量的值*/
if(*(ip_addr+i)=='.')
{
ip=ip*0x100+j;
j=0;
}
/*往临时变量中写入当前读取到的IP字段中的字符值
叠加乘以10,因为输入的IP地址是10进制*/
else
{
/*判断,如果输入的IP地址不规范,不是10进制字符
函数将返回0*/
if(beNumber(*(ip_addr+i))==0)
j=j*10+*(ip_addr+i)-'0';
else
return 0;
}
}
/*IP字段有4个,但是‘.’只有3个,叠加第四个字段值*/
ip=ip*0x100+j;
return ip;
};
/*显示logo信息*/
void logo(void)
{
printf("=============================================================================\n");
printf("--- Get the IP info.s from QQWry.dat v0.1 by dorainm dorainm@gmail.com ---\n");
printf("=============================================================================\n");
};
/*显示程序语法*/
void usage(char *app_name)
{
printf("\nUsage : %s [options]\n",app_name);
printf("options:\n");
printf(" -a <address> Search and display the Informations by Location Address.(*)\n");
printf(" -i <IP> Search and display the Informations by IP Address.\n");
printf(" -o <FILE> Output all the informations to a text file.\n");
printf(" -local Display the localhost IP's informations.(*)\n");
printf(" -updata Update the QQWry.dat from the Internet.(*)\n\n");
printf("ps: the optionss marked (*) are incompleted.\n");
};
/*显示结束信息*/
void showend(void)
{
printf("\n\nThe command completed successfully.\n\n");
};
/*主函数*/
int main(int argc, char *argv[])
{
FILE *fp; /*打开QQWry.dat的文件指针*/
unsigned long index_start,index_end,current; /*索引部分的起始位置的文件偏移量
索引部分的结束位置的文件偏移量
待搜索IP地址的索引条目的文件偏移量*/
char *country; /*国家位置*/
char *location; /*地域位置*/
country=(char*)malloc(MAXBUF);
location=(char*)malloc(MAXBUF);
logo();
if(argc<3)
{
usage(argv[0]);
showend();
return 1;
}
/*打开QQWry.dat文件*/
if((fp=fopen(QQWRY,"rb"))==NULL)
{
printf("[-] Error : Can not open the file %s.\n",QQWRY);
showend();
return 2;
}
else
printf("[+] Open the file [ %s ] successfully.\n",QQWRY);
/*显示QQWry.dat文件信息*/
getHead(fp,&index_start,&index_end);
getAddress(fp,getValue(fp,index_end+4,3),&country,&location);
printf("[+] Version of QQWry.dat : [ %s %s ]\n",country,location);
printf("[+] Index Location [ 0x%X - 0x%X ].\n",index_start,index_end);
/*判断第一个参数的值*/
if((strncmp(argv[1],"-i",2)==0)||(strncmp(argv[1],"-I",2)==0))
{
/*-i参数,搜索IP*/
unsigned long ip;
ip=getIP(argv[2]);
if(ip==0)
{
printf("[-] Error : the IP Address inputed.\n");
showend();
return 3;
}
/*搜索IP在索引区域的条目的偏移量*/
current=searchIP(fp,index_start,index_end,ip);
printf("[+] Address of index for [ %X ] is %X\n",ip,current);
/*获取该IP对因的国家地址和地域地址*/
getAddress(fp,getValue(fp,current+4,3),&country,&location);
printf("[+] Get the location for the IP address.\n");
printf("[+] [ IP Address ] %d.%d.%d.%d\n",(ip&0xFF000000)>>0x18,(ip&0x00FF0000)>>0x10,(ip&0x0000FF00)>>0x8,ip&0x000000FF);
printf("[+] [ Location ] %s %s\n",country,location);
}
else if((strncmp(argv[1],"-o",2)==0)||(strncmp(argv[1],"-O",2)==0))
{
/*-o参数,解压缩数据库,导出IP信息到文本文件*/
FILE *out;
unsigned long num;
if((out=fopen(argv[2],"w"))==NULL)
{
printf("[-] Error create the output text file [ %s ].\n","out.txt");
showend();
}
else
{
printf("[+] Create the output text file [ %s ] successfully.\n","out.txt");
}
/*导出IP条目信息*/
printf("[+] Outputing the informations ...");
num=putAll(fp,out,index_start,index_end);
printf("Finished.\n");
fclose(out);
/*显示导出条目的数量*/
printf("[+] The Total items number is [ %d ].",num);
}
/*关闭文件指针,释放变量空间,结束程序*/
fclose(fp);
free(country);
free(location);
showend();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -