per linux stai tranquillo... ho fatto anche una versione migliorata =) eccola:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#define PORT 80
void usage(char *argv, int h){
if(h){
printf("Usage:\n%s <1° part of url> <last part of url> [starting number for 2° part of url] [ending number]\n", argv);
printf("Create strings www.arg1-number.arg2 (without \"-\") where number goes from arg3 to arg4\n");
printf("and tries to connect to each site. If there\'s no arg3 it is set to 0, and if there\'s no arg4\n");
printf("it is set to 1000.\n");
}
else printf("Try\n%s -h\n", argv);
exit(0);
}
int main(int argc, char *argv[]){
char string1[30], string2[10];
int start=0, c=0, end;
int fd;
struct hostent *he;
struct sockaddr_in server;
if(argc<2) usage(argv[0], 0);
if(!strcmp(argv[1], "-h")) usage(argv[0], 1);
if(argc<3) usage(argv[0], 0);
if(argv[3]) start=atoi(argv[3]);
else start=0;
if(argv[4]) end=atoi(argv[4]);
else end=1000;
for(;start<=end;start++){
strcpy(string1, "www.");
strcat(string1, argv[1]);
strcat(string1, ".");
if(argv[3]){
sprintf(string2, "%i", start);
strcat(string1, string2);
}
strcat(string1, argv[2]);
if((he = gethostbyname(string1)) == NULL){
continue;
}
if((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
continue;
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(server.sin_zero), 8);
if(connect(fd, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -1){
continue;
}
else {close(fd);c=1;break;}
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen