Copy Link
Add to Bookmark
Report
strscan2b1.c
Scans a range of ips on a given port for (string). (In our honest opinion #1)
/* ( IOHO 2001 #og irc.ndrsnet.com ) */
/* strscan.c v2b1 by ka0z@ndrsnet for IOHO E-Zine http://chickenz.net/og */
/* Basically, I made this for myself and it was suggested that I put */
/* this in the e-zine so I did. Any ideas on how to implement the */
/* multiple line banner checking would be greatly appreciated. */
/* this has been optimized with ntohl and htonl and shit like that blah */
/* blah blah blah.....ok */
#include <stdio.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
int usage(char *);
int validip(char *);
int main(int argc, char *argv[]){
struct sockaddr_in sin;
struct in_addr addr;
unsigned long start,end;
long i;
int sock;
char buff[1024],*str,*check;
if(argc<5)
usage(argv[0]);
if(validip(argv[1]) || validip(argv[2])){
printf("you stupid jew you dont even know what the hell an ip is do you?\n");
exit(-1);
}
start=inet_addr(argv[1]);
end=inet_addr(argv[2]);
str=argv[4];
for(i=ntohl(start);i<=ntohl(end);i++){
if((i&0xff)==255)
i++;
if((i&0xff)==0)
i++;
addr.s_addr=htonl(i);
sin.sin_addr.s_addr=addr.s_addr;
sin.sin_port=htons(atoi(argv[3]));
sin.sin_family=AF_INET;
if((sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))<0){
perror("socket");
exit(-1);
}
if(connect(sock,(struct sockaddr *)&sin,sizeof(struct sockaddr_in))==-1)
goto err;
read(sock,buff,1024);
check=&buff[0];
if(*check == '\n')
goto err;
if(strstr(buff,str)){
printf("%s\n",inet_ntoa(addr));
fflush(stdout);
break;
}
err:
bzero((char *)&sin,sizeof(struct sockaddr_in));
bzero(buff,sizeof(buff));
close(sock);
}
exit(0);
}
int validip(char *ip){ /* props to mixter for this function :) */
int a,b,c,d,*check;
sscanf(ip,"%d.%d.%d.%d",&a,&b,&c,&d);
check=&a;
if(*check<0)
return(-1);
if(*check>255)
return(-1);
check=&b;
if(*check<0)
return(-1);
if(*check>255)
return(-1);
check=&c;
if(*check<0)
return(-1);
if(*check>255)
return(-1);
check=&d;
if(*check<0)
return(-1);
if(*check>255)
return(-1);
return(0);
}
int usage(char *p){
printf("strscan v2b1 by ka0z for IOHO\n"
"usage: %s <begin ip> <end ip> <port> <string>\n",p);
exit(-1);
}