⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getkeys.cpp

📁 WEB上实现的局域网FTP搜索程序
💻 CPP
字号:
#include <errno.h>#include "conf.h"union TripleField {     TripleField *lower[TOP256];    char ok[TOP256];};TripleField TFtoplevel;int count;FILE* output;void Process(char *buf){    int i, len, b;    char *key;    unsigned char *low, *li, c;    TripleField *TFptr;    bool valid;    len = strlen(buf);    if (len < KEYSIZE) return;    low = new (unsigned char)[len];    li = low;    for (key = buf, li = low; (*key != 0); key++, li++)	*li = tolower(*key);    key = buf;    b = 0;    while (*(key+KEYSIZE-1) != 0)    {	TFptr = &TFtoplevel;	for (i = 0; i < KEYSIZE-1; i++)	{	    c = low[b+i];	    if (!TFptr->lower[c]) 	    {		TFptr->lower[c] = new TripleField;		memset(TFptr->lower[c], 0, sizeof(TripleField));	    }	    TFptr = TFptr->lower[c];		}	c = low[b+KEYSIZE-1];	TFptr->ok[c] = 1;		key++;	b++;    }    delete low;}void DumpTriples(char *prefix, TripleField *ptr, int depth){    int i;    char newkey[KEYSIZE+1];    if (depth == (KEYSIZE-1))     {        for (i = 0; i < TOP256; i++)             if (ptr->ok[i]) 	    {		fprintf(output, "%s%c\n", prefix, i);		count++;	    }    }    else     {        for (i = 0; i < TOP256; i++)             if (ptr->lower[i] != NULL)             {                sprintf(newkey, "%s%c", prefix, i);                DumpTriples(newkey, ptr->lower[i], depth+1);            }    }}void MakeFileList(){    int cnt = 0;    char fn[1024];    FILE *f;    DIR *dir;    struct dirent* ent;    f = fopen(DBHOSTS, "w");    dir = opendir("ftpdata");    while (ent = readdir(dir))    {	if (strstr(ent->d_name, ".dat") == NULL) continue;	cnt++;	strcpy(fn, ent->d_name);	fn[strlen(fn)-4] = 0;	fprintf(f, "%d %d %s\n", cnt, 1, fn);    }    fclose(f);}int main(int argc,char *argv[]){    char buffer[MAX], *ptr;    int c, on;    char fn[1024], host[1024];    FILE *input, *filelist;    count = 0;    MakeFileList();    filelist = fopen(DBHOSTS, "r");    while (!feof(filelist))    {	fscanf(filelist, "%d %d %s\n", &c, &on, host);	sprintf(fn, "ftpdata/%s.dat", host);	printf("scaning... %s\n", fn);	if ((input = fopen(fn, "r")) != NULL)	{	    while (!feof(input)) 	    {		fgets(buffer, MAX, input);		if (feof(input)) break;		if ((ptr = strstr(buffer, "!!"))!=NULL) *ptr='\0';		ptr=buffer+strlen(buffer);		while (ptr!=buffer && *ptr!='/') ptr--;		if (*ptr=='/') ptr++;		Process(ptr);	    }	    fclose(input);	}	else 	{	    fprintf(stderr, "Cannot open %s\n", fn);	}    }    output = fopen(DBKEYS, "w");    DumpTriples("", &TFtoplevel, 0);    fclose(output);    printf("Got %d keys.\n", count);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -