linuxuser 0 Report post Posted June 9, 2004 Writing a C++ socket program that scans given range of port number and tells u which ones are available is not hard at all. The following code does just that. It takes 3 arguments. First one is host ip address, second one is lower range and third one is higher range of port #. Eg--> Nameof Exe( portscan.exe) 127.0.0.1 0 80 #include<stdio.h> #include<winsock2.h> int main( int argc, char* argv[] ){ if( argc != 4 ){ printf("Invalid arguments"); return 0; } SOCKET s; struct sockaddr_in address; s = socket( AF_INET, SOCK_STREAM, 0 ); address.sin_family = AF_INET; address.sin_addr.s_addr = inet_addr((char *)argv[1]);//INADDR_ANY; int port = 0; for( port=atoi( argv[2]); port<= atoi( argv[3] ); port++ ){ address.sin_port = htons( port ); if( connect(s, (struct sockaddr*)&address, sizeof( address )) == 0 ){ printf("Port:"); printf("%d", port ); printf(" open\n" ); closesocket( s ); s = socket( AF_INET, SOCK_STREAM, 0 ); } } closesocket( s ); return 1; } Quote Share this post Link to post Share on other sites
Limitation//Moon 0 Report post Posted June 9, 2004 Thanks rs, keep us giving more, BTW do you have any packet scan one? Quote Share this post Link to post Share on other sites
webber 0 Report post Posted June 10, 2004 yaa i can check your code too but I lost my C compiler ... umm anyway I have copied down in my box and will check that out .. thanx for that Quote Share this post Link to post Share on other sites
linuxuser 0 Report post Posted June 10, 2004 Get a free C/C++ compiler/IDE Dev-C++ - http://www.bloodshed.net/ Quote Share this post Link to post Share on other sites
webber 0 Report post Posted June 11, 2004 QUOTE (rs_1915 @ Jun 10 2004, 07:49 PM) Get a free C/C++ compiler/IDE Dev-C++ - http://www.bloodshed.net/ thanx for that site ........... Quote Share this post Link to post Share on other sites