/***********************************************
 * Carlos Augusto :: vendetta [at] zonartm.org *
 * RTM Security Team :: www.zonartm.org        *
 * vPortScanner v 0.1                          *
 * *********************************************/

#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>

/********** TCP Standar Ports **********/
int tcp_ports[]={	21, /* FTP */
					22, /* SSH */
					23, /* SMTP */
					25, /* Telnet */
					53, /* DNS */
					80, /* HTTP */
					110, /* POP3 */
					139, /* NETBIOS Session Service */
					389, /* LDAP */
					443, /* SSL */
					3306, /* MySQL */
					8080, /* Proxy */
					55555 /* Metasploit web server */
};


int main(int argc,char *argv[]){
	printf("\nvPortScanner v0.1\n");
	
	char *IP;
	IP=argv[1];
	struct sockaddr_in host;
	struct hostent *host_name;
	int socketfd, i;
		
	if((strlen(IP)>15) || argv[2]!=NULL){
		printf("ERROR: I have problems with de IP, maybe is wrong!\n");
		return (-1);
	}
	
	printf("Scanning %s\n\tPORT\tSTATE\n", IP);
	host_name=gethostbyname(argv[1]);
	
	for(i=0; i<13; i++){
		host.sin_family=AF_INET;
		host.sin_addr=*((struct in_addr*)host_name->h_addr);
		host.sin_port=htons(tcp_ports[i]);
		
		bzero(&(host.sin_zero), 8);
		socketfd=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		
		if((connect(socketfd, (struct sockaddr *)&host, sizeof(host)))!=(-1)){
			printf("\t%d\tOPEN\n", tcp_ports[i]);
		}
		else{
			printf("\t%d\tCLOSE\n", tcp_ports[i]);
		}
		close(socketfd);
		
	}
	return 0;
}