int searchLocal(IpStruct tmp, unsigned int iplong, FILE * db, char * local) {
    char buf[80] = {0};
    int tmpCount;
    int pos = BYTE3INT(tmp.local);
    printf("local pos: %d\n", pos);
    fseek(db, pos, SEEK_SET);
    fread(buf, 4, 1, db);
    int c = compare(buf, iplong);
    printf("is compare: %d\n", c);

    fread(buf, 1, 1, db);
    if (buf[0] == 0x01) {
        fread(buf, 3, 1, db);
        pos = BYTE3INT(buf);
        fseek(db, pos, SEEK_SET);
        fread(buf, 1, 1, db);
    }

    if (buf[0] == 0x02) {
        fread(buf, 3, 1, db);
        tmpCount = ftell(db);
        pos = BYTE3INT(buf);
        fseek(db, pos, SEEK_SET);
        fread(buf, 1, 1, db);
    }

    if ( buf[0] ) {
        GetData(buf+1, db, 40);
    }
    printf("local: %s\n", local);
    strcat(local, (char*)buf);
    printf("local: %s\n", local);

    // 获取地区
    if ( tmpCount ) {
        fseek(db, tmpCount, SEEK_SET);
    }
    fread(buf, 1, 1, db);
    while ( buf[0] == 0x02 ) {
        // 获取地区偏移
        fread(buf, 3, 1, db);
        pos = BYTE3INT(buf);
        fseek(db, pos, SEEK_SET);
        fread(buf, 1, 1, db);
    }
    if ( buf[0] == 0x01 || buf[0] == 0x02 ) {
        strcat(local, "未知");
        return 0;
    }
    if ( buf[0] ) {
        GetData(buf+1, db, 40);
    }
    strcat(local, (char*)buf);
    printf("local: %s\n", local);

    return 0;
}
Exemple #2
0
int searchAreaAddr(FILE * db, char * local) {
    int pos = 0;
    char buf[80] = {0};
    fread(buf, 1, 1, db);
    if (buf[0] == 0x02 ) {
        // 获取地区偏移
        fread(buf, 3, 1, db);
        pos = BYTE3INT(buf);
        fseek(db, pos, SEEK_SET);
        fread(buf, 1, 1, db);
    }
    if ( buf[0] == 0x01 || buf[0] == 0x02 ) {
        strcat(local, "未知");
        return 0;
    }
    if ( buf[0] ) {
        GetData(buf+1, db, 40);
    }
    strcat(local, (char*)buf);
}
Exemple #3
0
 int main()
{
	FILE *fp,*fpout;
	unsigned headpos,tailpos;
	int pos,curpos,offset,amount;
	unsigned char buf[80],content[200];
	struct INDEXITEM tmp;
	fp=fopen("QQWry.Dat","r");
	if(!fp){
		printf("cannot open file QQWry.Dat!");
		exit(0);
	}
	fpout=fopen("ip_arrange.txt","w");
	if(!fp){
		printf("cannot open file ip_arrange.txt!");
		exit(0);
	}
	fread(&headpos,sizeof(headpos),1,fp);
	fread(&tailpos,sizeof(tailpos),1,fp);
	amount = (tailpos - headpos)/sizeof(struct INDEXITEM);
//	printf("共有%d条记录.\n",amount+1);
	for(offset=0;offset<=amount;offset++){
		fseek(fp,headpos+offset*sizeof(tmp),SEEK_SET);
		fread(&tmp,sizeof(tmp),1,fp);
		//ip地址段开始
		fprintf(fpout,"%03u.%03u.%03u.%03u ",tmp.ip[3],tmp.ip[2],tmp.ip[1],tmp.ip[0]);
		pos = BYTE3INT(tmp.offset);
		fseek(fp, pos, SEEK_SET);
		fread(buf, 4, 1, fp);
		//ip地址段结束
		fprintf(fpout, "%03u.%03u.%03u.%03u ", buf[3], buf[2], buf[1],
		buf[0]);
		fread(buf, 1, 1, fp);
		if ( buf[0] == 0x01 ) { // 国家地区均重复, 跳转至新地址
			fread(buf, 3, 1, fp);
			pos = BYTE3INT(buf);
			fseek(fp, pos, SEEK_SET);
			fread(buf, 1, 1, fp);
		}
		curpos=0;

		// 获取国家
		if ( buf[0] == 0x02 ) {
			// 获取国家偏移
			fread(buf, 3, 1, fp);
			// 保存地区信息
			curpos = ftell(fp);
			pos = BYTE3INT(buf);
			fseek(fp, pos, SEEK_SET);
			fread(buf, 1, 1, fp);
		}
		if ( buf[0] == 0x01 || buf[0] == 0x02 ) {
			printf("There is something wrong....\n");
			return  -1;
		}

		if ( buf[0] )
			getData(buf+1, fp, 60);
		if (!strcmp(buf, " CZ88.NET"))
			strncpy(content, "未知地址", sizeof (content));
		else
			sprintf(content, "[%s]", buf);

		// 获取地区
		if ( curpos )
			fseek(fp, curpos, SEEK_SET);
		fread(buf, 1, 1, fp);
		while ( buf[0] == 0x02 ) {
			// 获取地区偏移
			fread(buf, 3, 1, fp);
			pos = BYTE3INT(buf);
			fseek(fp, pos, SEEK_SET);
			fread(buf, 1, 1, fp);
		}
		if ( buf[0] == 0x01 || buf[0] == 0x02 ) {
			printf("There is something wrong....\n");
			return -1;
		}
		if ( buf[0] )
			getData(buf+1, fp, 80);
		//去掉这个CZ88.NET
		if(strcmp(buf," CZ88.NET"))
			strcat(content,buf);
		//else
		//	strcat(content,"未确定的地址");
		//ip的位置
		fprintf(fpout,"%s\n",content);
	}
	fclose(fp);
	fclose(fpout);
	return 0;
}
Exemple #4
0
int searchLocal(IpStruct tmp, unsigned int iplong, FILE * db, char * local) {
    char buf[80] = {0};
    int first = 0;
    int offset = 0;
    int countPos= 0;
    int tmpCount = 0;
    int pos = BYTE3INT(tmp.local);
    fseek(db, pos, SEEK_SET);
    fread(buf, 4, 1, db);
    int c = compare(buf, iplong);

    // 获取资料
    fread(buf, 1, 1, db);
    if ( buf[0] == 0x01 ) { // 国家地区均重复, 跳转至新地址
        fread(buf, 3, 1, db);
        pos = BYTE3INT(buf);
        fseek(db, pos, SEEK_SET);
        fread(buf, 1, 1, db);
    }

    // 获取国家
    if ( buf[0] == 0x02 ) {
        // 获取国家偏移
        fread(buf, 3, 1, db);
        // 保存地区信息
        tmpCount = ftell(db);
        pos = BYTE3INT(buf);
        fseek(db, pos, SEEK_SET);
        fread(buf, 1, 1, db);
    }
    if ( buf[0] == 0x01 || buf[0] == 0x02 ) {
        strcat(local, "未知");
        return;
    }

    if ( buf[0] ) {
        GetData(buf+1, db, 40);
    }
    strcat(local, (char*)buf);
    strcat(local, " ");

    // 获取地区
    if ( tmpCount ) {
        fseek(db, tmpCount, SEEK_SET);
    }
    fread(buf, 1, 1, db);
    while ( buf[0] == 0x02 ) {
        // 获取地区偏移
        fread(buf, 3, 1, db);
        pos = BYTE3INT(buf);
        fseek(db, pos, SEEK_SET);
        fread(buf, 1, 1, db);
    }
    if ( buf[0] == 0x01 || buf[0] == 0x02 ) {
        strcat(local, "未知");
        return;
    }
    if ( buf[0] ) {
        GetData(buf+1, db, 40);
    }
    strcat(local, (char*)buf);
    return;
}