#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <arpa/inet.h>
#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<n;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;
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
本文題目:后臺掃描,網(wǎng)測通過-創(chuàng)新互聯(lián)
地址分享:http://jinyejixie.com/article34/pijse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、營銷型網(wǎng)站建設(shè)、ChatGPT、移動網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容