?? dns.cpp
字號:
#include "stdafx.h"
#include "dns.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#include <windows.h>
#include <process.h>
struct MMyFileHeader *loadArray(char *inFileName, char **file_in, int *count)
{
FILE *inFile;
unsigned long temp=0;
struct MMyFileHeader *header;
header=(struct MMyFileHeader *)malloc(sizeof(struct MMyFileHeader));
memset(header,0,sizeof(struct MMyFileHeader));
if ((inFile = fopen(inFileName, "rb")) == NULL)
{
fprintf(stderr,"Error opening input file, %s\n", inFileName);
return NULL;
}
fread(&header->Size,1,4,inFile);
fread(&header->Index,1,4*26,inFile);
fread(&header->count,1,4,inFile);
(*file_in)=(char *)malloc(header->Size-28*4);
if ((*file_in) == NULL)
{
fprintf(stderr, "Malloc of array in loadArray failed!\n");
return NULL;
}
memset(*file_in,0,header->Size-28*4);
fread((*file_in),1,header->Size-28*4,inFile);
fclose(inFile);
printf("Reading file %s (each . is 1000 words read)\n", inFileName);
*count = header->count;
return header;
}
int isString(char *file_in,char *word)
{
char *ptemp=NULL;
ptemp=file_in;
while((*ptemp)!='\n')
ptemp++;
memcpy(word,file_in,ptemp-file_in);
return 1;
};
int LoadDate(char *inFileName, char **file_in, int *count)
{
FILE *inFile;
int Size;
if ((inFile = fopen(inFileName, "rb")) == NULL)
{
fprintf(stderr,"Error opening input file, %s\n", inFileName);
return 0;
}
fread(&Size,1,4,inFile);
fseek(inFile,27*4,SEEK_SET);
fread(count,1,4,inFile);
(*file_in)=(char *)malloc(Size-28*4);
memset(*file_in,0,Size-28*4);
fread((*file_in),1,Size-28*4,inFile);
fclose(inFile);
return 1;
}
unsigned _stdcall ip_d(LPVOID myarg) //ip查DOMAIN
{
char *word;
char filename[WORD_LENGTH];
int No;
int j=0;
int k=0;
char *array;
int count;
char out[WORD_LENGTH];
char *gc;
char *p;
char *Domin;
word=((struct MyArg *)myarg)->find;
No=((struct MyArg *)myarg)->k;
switch(No)
{
case 0:strcpy(filename,"G:\\\\com") ;break;
case 1:strcpy(filename,"G:\\\\cn") ;break;
case 2:strcpy(filename,"G:\\\\net") ;break;
case 3:strcpy(filename,"G:\\\\hk") ;break;
case 4:strcpy(filename,"G:\\\\org") ;break;
}
if (!LoadDate(filename,&array,&count))
{
fprintf(stderr," loadArray failed! Program terminating...\n");
return EXIT_FAILURE;
}
if((gc=strstr(array,word)))
{
memset(out,0,WORD_LENGTH);
for(Domin=gc;(*Domin)!='\n';Domin--);
memcpy(out,Domin+1,gc-Domin-2);
p=filename;
while(*(p++)=='\\');
strcat(out,".");
strcat(out,p+3);
if(No!=0)
strcat((*((struct MyArg *)myarg)->dns_result),";");
strcat((*((struct MyArg *)myarg)->dns_result),out);
}
else printf("%s ignored(not found) in %s !\n",word,filename);
free(array);
}
char *Word_Postfix(char *in,char *open)
{
char *p;
char *org=in;
char ptem[WORD_LENGTH]="";
while(*(in++)!='.');
p=in;
while(*(++p)!=0);
memcpy(ptem,in,p-in);
sprintf(open,"G:\\\\%s",ptem);
*(--in)=0;
strcpy(ptem,org);
memset(org,0,WORD_LENGTH);
strcpy(org,ptem);
return ptem;
}
void d_ip(char **wordArray, int *count,char *word1,char **dns_result) //DOMAIN查ip
{
char word[WORD_LENGTH];
char IP[WORD_LENGTH];
char Postfix[WORD_LENGTH];
char openfile[WORD_LENGTH];
char *p;
char *p2;
int found=0;
struct MMyFileHeader *header;
memset(word,0,WORD_LENGTH);
memset(IP,0,WORD_LENGTH);
memset(Postfix,0,WORD_LENGTH);
memset(openfile,0,WORD_LENGTH);
printf("Domain Name = %s,",word1);
strcpy(word,word1);
Word_Postfix(word,openfile);
if (!(header=loadArray(openfile,wordArray,count)))
{
fprintf(stderr," loadArray failed! Program terminating...\n");
}
p2=*wordArray+header->Index[word[0]-'a']-28*4;
while(p=strstr(p2,word))
{
p2=p;
if(*(p-1)!='\n'){
while((*p2++)!='\n');
continue;
}
p+=strlen(word);
if((*p)!='_'){
while((*p2++)!='\n');
continue;
}
p++;
memset(IP,0,WORD_LENGTH);
if(isString(p,IP))
{
fflush(stdout);
fprintf(stderr,"%s IP Address is %s \n",word1,IP);
found=1;
}
while((*p2++)!='\n');
}
if(!found)
{
printf("%s ignored(not found)!\n",word1);
sprintf(IP,"(not found)!\n");
//return;
}
free(header);
memcpy(*dns_result,IP,sizeof(IP));
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -