用c写了个后台扫描
/** * Notice: The program is not debug on internet and not use thread supervene. * date : 6-26 * author: jker **/#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>#define LINE 1024#define dict "dict.txt"#define result "manager.txt"void itos(int num,char *str){ int a=num; int x,y,z; x=a/100; y=a%100/10; z=a%10; if(x==0){ if(y==0){ str[0]+=z; str[1]='/0'; }else{ str[0]+=y; str[1]+=z; str[2]='/0'; } }else{ str[0]+=x; str[1]+=y; str[2]+=z; str[3]='/0'; } return;}char *nip(char *oip){ char *str[4]={""},*rtn; char *delim = "."; char * tmp; int i=0; char arr[4]={48,48,48,'/0'}; rtn = malloc(512); memset(rtn,'/0',512); tmp = strtok(oip,delim); str[i++]=tmp; while(tmp=strtok(NULL,delim)){ str[i++]=tmp; } for(i=3;i>=0;i--){ if(atoi(str[i])<255){ itos(atoi(str[i])+1,arr); str[i]=arr; break; } } for(i=0;i<4;i++){ strcat(rtn,str[i]); if(i<3)strcat(rtn,delim); } return rtn;}int main(int argc,char *argv[]){ int sc,fd; unsigned short port = 80; struct sockaddr_in add; char *ip,*sip,*eip; struct hostent *host; char rheader[LINE],dictbuf[LINE],resbuf[LINE]; char *dir,path[LINE]="",*arr[LINE],*tmp,state[3],manager[LINE]; int i=0,n=0,bytes; if(argc != 3){ printf("please input startIp and endIp./r/n"); return -1; } 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); sip = argv[1]; eip = argv[2]; strcpy(ip,sip); memset(manager,'/0',LINE); memset(rheader,'/0',LINE); sc = socket(AF_INET,SOCK_STREAM,0); if(sc == -1){ printf("create socket fail!/r/n"); return -1; } printf("create socket ok./r/n"); 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); do{ host = gethostbyaddr(ip,strlen(ip),AF_INET); if(host == (struct hostent *)NULL) { printf("can`t get host from %s/r/n",ip); if(strcmp(ip,eip)<0)ip=nip(ip); continue; }else{ printf("host name:%s/n",host->h_name); } 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++){ strcat(rheader,"HEAD "); strcat(rheader,arr[i]); strcat(rheader," HTTP/1.1"); strcat(rheader,"/r/n"); strcat(rheader,"Host:"); strcat(rheader,host->h_name); strcat(rheader,"/r/n"); //strcat(rheader,"Accept:*//*"); //strcat(rheader,"/r/n"); strcat(rheader,"Connection:Keep-Alive"); strcat(rheader,"/r/n"); write(sc, rheader, strlen(rheader));usleep(100); bytes = read(sc, resbuf, LINE); printf("Response from %s:/n",ip); write(STDOUT_FILENO, resbuf, bytes); for(i=0;i<3;i++){ state[i]=resbuf[i+9]; } if(!((state>="400" && state<="450")||state=="500")){ strcat(manager,"http://"); strcat(manager,host->h_name); strcat(manager,arr[i]); strcat(manager,"/r/n"); write(fd,manager,sizeof(manager)); } } close(sc); ip = nip(ip); }while(strcmp(ip,eip)<0); close(fd); return 0;}
>更多相关文章
- 09-26多线程开发中线程数量设计问题
- 09-26Go语言和Java、Python等其他语言的对比分析
- 09-26Java语言为什么经久不衰?且总能霸占编程语言排行榜首?
- 09-26浅谈10个提升应用程序10倍性能的技巧
- 06-10利用Python语言判断狗狗年龄的程序
- 12-09用c写了个后台扫描
首页推荐
佛山市东联科技有限公司一直秉承“一切以用户价值为依归
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 12-05亚马逊推出新一代基础模型 任意模态生成大模
- 12-05OpenAI拓展欧洲业务 将在苏黎世设立办公室
- 12-05微软质疑美国联邦贸易委员会泄露信息 督促其
- 12-05联交所取消宝宝树上市地位 宝宝树:不会对公
- 12-04企业微信致歉:文档打开异常已完成修复
相关文章
24小时热门资讯
24小时回复排行
热门推荐
最新资讯
操作系统
黑客防御