Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TCP Portscanner by iotpackets & netflooding
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/time.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <net/if.h>
- #include <netinet/ip.h>
- #include <netinet/tcp.h>
- #include <errno.h>
- #include <netdb.h>
- int Timeout;
- int least;
- int max;
- int resolve(char * , char *);
- int resolve(char * site , char* ip)
- {
- struct hostent *he;
- struct in_addr **addr_list;
- int i;
- if ( (he = gethostbyname( site ) ) == NULL)
- {
- // get the host info
- herror("gethostbyname");
- return 1;
- }
- addr_list = (struct in_addr **) he->h_addr_list;
- for(i = 0; addr_list[i] != NULL; i++)
- {
- //Return the first one;
- strcpy(ip , inet_ntoa(*addr_list[i]) );
- return 0;
- }
- return 1;
- }
- void portscan(char *target, int port)
- {
- int Socket;
- struct timeval timeout;
- struct sockaddr_in sock;
- if(Timeout < 0 || Timeout == 0)
- Timeout = 3; // set to 3 for default
- timeout.tv_sec = Timeout;
- timeout.tv_usec = 0;
- Socket = socket(AF_INET, SOCK_STREAM, 0);
- setsockopt(Socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
- setsockopt(Socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
- sock.sin_family = AF_INET;
- sock.sin_port = htons(port);
- sock.sin_addr.s_addr = inet_addr(target);
- if(connect(Socket, (struct sockaddr *)&sock, sizeof(sock)) == -1)
- goto end;
- else
- {
- printf("[\x1b[32m+\x1b[37m] Open Port %s:%d open!\n", target, port);
- goto end;
- }
- end:
- close(Socket);
- return;
- }
- int main(int argc, char **argv)
- {
- if(argc < 5 || argc > 5)
- {
- printf("[\x1b[31m?\x1b[37m] Usage: %s <host> <least> <max> <timeout>\n", argv[0]);
- exit(0);
- }
- char host[60];
- resolve(argv[1], host);
- printf("[\x1b[34m!\x1b[37m] Portscanner started on %s\n", host);
- least = atoi(argv[2]);
- if(least == 0 || least < 0)
- least = 1;
- max = atoi(argv[3]);
- if(max == 0 || max < 0)
- max = 500;
- Timeout = atoi(argv[4]);
- int port;
- for(port=least; port < max; port++)
- {
- portscan(host, port);
- }
- printf("[\x1b[33m?\x1b[37m] Finished, Scanned ports %d - %d\n", least, max);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement