hi heres some basic question why this darn scanner isnt working.
even when i am using it correct (with 2 arguments)Code:#include <stdio.h> #include <sys/types.h> #include <sys/types.h> #include <netdb.h> #include <netinet/in.h> //void print(int status); int main (int argc, char *argv[]) { int sockfd; struct sockaddr_in dest; struct hostent *he; int i = 0; int start_port = atoi(argv[2]); if (argc < 2); { printf("usage: %s <hostname/ip> <startport>\n", argv[0]); exit(-1); } if ((he = gethostbyname(argv[1])) == NULL) { perror("gethostbyname"); exit (-1); } for(i= start_port; i < 65535; i++) { if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == - 1) { perror("socket"); exit(-1); } dest.sin_family = AF_INET; dest.sin_port = htons(i); dest.sin_addr = *((struct in_addr *)he->h_addr); if(connect(sockfd, (struct sockaddr *)&dest, sizeof(struct sockaddr)) == -1) { printf("port %d\t Closed\n", i); close(sockfd); sleep(1); } else { printf("port %d\t opened\n", i); close(sockfd); sleep(1); } } return 0; }
it prints out the string it is supposed to do when to
few arguments were given.
whats wrong?
thank you



LinkBack URL
About LinkBacks


