后台扫描,网测通过

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define LINE 1024
#define dict "dict.txt"
#define result "manager.txt"

int main(int argc,char *argv[]){
 int sc,fd;
 unsigned short port = 80;
 struct sockaddr_in add;struct in_addr in;
 char *ip;
 struct hostent *host;
 char rheader[LINE],dictbuf[LINE],resbuf[LINE];
 char *dir,path[LINE]="",*arr[LINE],*tmp,state[3],manager[LINE];
 int i=0,j,n=0,bytes;

 if(argc != 2){
   printf("please input domain.\r\n");
   return;
 }

 dir = get_current_dir_name();
 strcat(path,dir);
 strcat(path,"/");
 strcat(path,dict);
 fd = open(path,O_RDONLY);
 read(fd,dictbuf,sizeof(dictbuf));
 close(fd);
 arr[n++]=strtok(dictbuf,"\r\n");
 while(tmp=strtok(NULL,"\r\n"))arr[n++]=tmp;

 ip = malloc(512);
 memset(ip,'\0',512);

 sc = socket(AF_INET,SOCK_STREAM,0);
 if(sc == -1){
   printf("create socket fail!\r\n");
   return;
 }

 bzero(&add,sizeof(add));
 add.sin_family=AF_INET;
 add.sin_port=htons(port);

 bzero(&path,sizeof(path));
 strcat(path,dir);
 strcat(path,"/");
 strcat(path,result);
 fd = open(path,O_WRONLY|O_CREAT|O_APPEND,S_IRWXU);

 if(!(host=gethostbyname(argv[1]))){
     fprintf(stderr,"Can`t resolve host.\n");
     exit(1);
 }

 memcpy(&add.sin_addr.s_addr,host->h_addr_list[0],4);
 in.s_addr = add.sin_addr.s_addr;
 printf("IP:%s\n",ip=inet_ntoa(in));

 add.sin_addr.s_addr=inet_addr(ip);
 if(connect(sc,(struct sockaddr *)(&add),sizeof(struct sockaddr))==-1){
   printf("conn fail!\r\n");
   return -1;
 }
 for(;i   memset(manager,'\0',LINE);
   memset(rheader,'\0',LINE);

   strcat(rheader,"HEAD ");
   strcat(rheader,arr[i]);
   strcat(rheader," HTTP/1.1");
   strcat(rheader,"\r\n");

   strcat(rheader,"Host:");
   strcat(rheader,argv[1]);
   strcat(rheader,"\r\n");

   strcat(rheader,"\r\n");
   printf("send:[\n%s\n]\n",rheader);
   write(sc, rheader, strlen(rheader));usleep(100);        
   bytes = read(sc, resbuf, LINE);        
   printf("Response from %s:[\n%s\n]\n",ip,resbuf);        

   for(j=0;j<3;j++){
     state[j]=resbuf[j+9];
   }
   printf("state:%s\n",state);
   if(!((strcmp(state,"400")>=0 && strcmp(state,"450")<=0)||strcmp(state,"500")==0)){
     strcat(manager,"http://");
     strcat(manager,argv[1]);
     strcat(manager,arr[i]);
     printf("********%s*******\n",manager);
     strcat(manager,"\r\n");
     write(fd,manager,sizeof(manager));
   }    
 }
 close(sc);  
 close(fd);
 return 0;
}

成都创新互联公司是一家集网站建设,宾阳企业网站建设,宾阳品牌网站建设,网站定制,宾阳网站建设报价,网络营销,网络优化,宾阳网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。


名称栏目:后台扫描,网测通过
文章源于:http://pwwzsj.com/article/pgophj.html