Jump to content


Photo

Network Programming:Simple portscan


  • Please log in to reply
4 replies to this topic

#1 linuxuser

linuxuser

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 1,147 posts

Posted 09 June 2004 - 06:43 PM

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;
}
:)

#2 Limitation//Moon

Limitation//Moon

    Advanced Honourable Member

  • National Committee
  • PipPipPipPipPip
  • 2,810 posts

Posted 09 June 2004 - 08:02 PM

Thanks rs, keep us giving more, BTW do you have any packet scan one?

#3 webber

webber

    WNSO Gold Member

  • WNSO Addict
  • PipPipPip
  • 440 posts

Posted 10 June 2004 - 07:36 PM

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
//
(,")/' Real Eyes - Realize - Real Lies
<||
./!.

Posted Image




My Personal Site:
http://www.sudeeptamrakar.com.np


#4 linuxuser

linuxuser

    Honourable Member

  • WNSO Addict
  • PipPipPipPip
  • 1,147 posts

Posted 10 June 2004 - 07:49 PM

Get a free C/C++ compiler/IDE smile.gif

Dev-C++ - http://www.bloodshed.net/
:)

#5 webber

webber

    WNSO Gold Member

  • WNSO Addict
  • PipPipPip
  • 440 posts

Posted 11 June 2004 - 04:39 AM

QUOTE (rs_1915 @ Jun 10 2004, 07:49 PM)
Get a free C/C++ compiler/IDE smile.gif

Dev-C++ - http://www.bloodshed.net/

thanx for that site ........... biggrin.gif
//
(,")/' Real Eyes - Realize - Real Lies
<||
./!.

Posted Image




My Personal Site:
http://www.sudeeptamrakar.com.np





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users