#include <sys/socket.h>
#include <signal.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int scann_normal(char *ip, int port);
int main(int argc, char *argv[])
{
char *ip;
unsigned int startport = 0;
unsigned int endport = 0;
unsigned int idle = 0;
int i = 0;
char *tmp;
int tmp2 = 0;
if (argc < 5)
{
printf ("Error : Incorrect usage.\n");
printf ("Usage : littlescanner -IP -startport -endport -idle [in ms].\n");
return 0;
}
if (strlen(argv[1]) > 15)
{
printf ("Error : The IP-Parameter is not a valid IP-adress\n");
return 0;
}
else
{
strcpy(ip,argv[1]);
};
tmp = argv[2];
tmp2 = atol (tmp);
if (tmp2 < 65535 && tmp2 > 0)
{
startport = tmp2;
}
else
{
printf ("Startport is not a valid Number.\n");
return 0;
}
tmp = argv[3];
tmp2 = atol (tmp);
if (tmp2 < 65535 && tmp2 > 0 && tmp2 > startport)
{
endport = tmp2;
}
else
{
printf ("Endport is not a valid Number. \n");
return 0;
}
idle = atol (argv[4]);
for (i = startport; i <= endport; i++)
{
scann_normal(ip,i);
}
}
int scann_normal(char *ip, int port)
{
int sockfd;
struct sockaddr_in servaddr;
servaddr.sin_family = AF_INET;
AF_INET
servaddr.sin_port = htons(port);
servaddr.sin_addr.s_addr = inet_addr(ip);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (connect(sockfd,(struct sockaddr *) &servaddr, sizeof(servaddr)) != -1)
printf ("Port %i is open\n",port);
close (sockfd);
}