Basic port scanner code .. pls help ???
Hello friends i have written a basic port scanner with options like :
1) The program will prompt for 3 command line arguments viz :
ip/hostname
start_port <mandatory>
end_port <optional>
out of this the end_port is optional if the user provides the
end port than it will scan till that port or else if the end port
is not provided then the scan will go from start_port till 65535.
2) The program open a log file named scanresults.txt at c:\
which contains all the scan results in it so user can check it after
the run.
3) The program shows only those ports, on the screen, which are open it will not display closed ports but they are logged into the file.
after the program run is complete user can check for the file at
c:\scanresults.txt
/****** problem ******/
But the real problem is that suppose when i am running the application as
c:\>port 111.111.111.111 138 139
where 138 is the start port and 139 is the end port
then it is showing both the ports closed.
but in turn if i am running the same application as
c:\>port 111.111.111.111 139 140
where 139 is the start port and 140 is the end port
then it is showing me port 139 open and 140 closed.
inshort if it encounters first port as closed it shows all the following ports closed
but it is not true vice versa.
i have gone through the code many a times but i can't figure it out what is the
problem..
anybody pls go through the code and pls tell me why its happening like this..
i will be very grateful .. thanks millions ..
/************************************************** ******/
the code is as follows :
******************** CODE ******************
#include <stdio.h>
#include <winsock.h>
FILE *fp;
char file_to_open [60];
int sock;
int count = 0;
int start_port;
int end_port = 0;
WSADATA wsaData;
struct hostent *host;
struct sockaddr_in dest;
void OpenFiles()
{
sprintf(file_to_open , "/scanresults.txt");
fp = fopen( file_to_open , "w" );
if( fp == NULL )
{
printf("File Open Error\n");
exit(1);
}
fprintf(fp,"\n************************************ ******************************" );
fprintf(fp,"\n ROOTSCAN LOG");
fprintf(fp,"\n************************************ ******************************\n" );
}
void CloseFiles()
{
fclose( fp );
}
int main(int argc, char *argv[])
{
if(argc < 3)
{
printf("\n\tUsage: %s <host/ip> <start_port> [end_port]\n", argv[0]);
exit(-1);
}
OpenFiles();
//windows specific code here
WSAStartup(MAKEWORD(1, 1), &wsaData);
//end here
start_port = atoi(argv[2]);
if( argc > 3)
end_port = atoi( argv[3] );
else
end_port = 65535;
if((host = gethostbyname(argv[1])) == NULL)
{
printf("Couldn't resolve %s\n", argv[1]);
exit(-1);
}
for(count = start_port; count <= end_port; count++)
{
if((sock = socket(AF_INET, SOCK_STREAM, 0)) == 0)
{
printf("Couldn't make socket!\n");
exit(-1);
}
dest.sin_family = AF_INET;
dest.sin_port = htons(count);
dest.sin_addr = *((struct in_addr *)host->h_addr);
if(connect(sock, (struct sockaddr *)&dest, sizeof(struct sockaddr)) == -1)
{
fprintf( fp ,"Port %5d Closed\n",count);
shutdown(sock, 2);//use this instead of close.
//windows...
WSACleanup();
//endsleep(1);
}
else
{
printf("Port %d \t Open\n", count);
fprintf( fp ,"Port %5d Open\n", count);
shutdown(sock, 2);//use this instead of close.
//windows...
WSACleanup();
//end
}
}//for loop end
CloseFiles();
return(0);
}
pls help waiting...
Dude, what are you doing?
Hey.
I don't mean to sound too rude, but that port-scanner is mine, down to the very last character.
I posted the earliest versions on HDC BBS, and several individuals helped me develop it further, and to port it onto Windows. It is a good job we have good people around like that.
Go to http://www.hackers.com/________.____...threadid=60775
and you will see that it is me who it the author of Rootscan, and it is you who ripped it from me. That link will take you to the very place you first aquired the code.
I expect a big apology from you, and I sure hope you feel ashamed and embarassed, you arrogant, ignorant, ripping piece of ****.
I don't know what the hell you think you were doing, but I do know the only person you were thinking of was yourself. You could've got permission to modify. You could've asked to borrow code. We could've worked something about. But no, that wasn't atcually your intension. What you wanted was, was to take the code, take away the credits, then post it, maybe to get more respect, or even higher status on the board. Either way, you won't be getting any of that now. (And for the record, life isn't about that.)
You aren't so cool now, huh? If you don't reply to this message with an apology, or you go try saying I am the one who ripped from YOU, or try to say it is some huge coincidence, you are a bigger coward, and more pig-headed, arrogant little **** than I thought. Just admit, you ripped it, you are implying that it is yours -- it isn't -- and you are just pure self-centered. You took away the credits, you claimed it as yours, and it is just as simple as that.
You need to feel long and hard before looking at another piece of code again, or try to write some (I put big emphasis on TRY) code.
So long.