scanning a network

This is a discussion on scanning a network within the Linux Programming forums, part of the Platform Specific Boards category; I made a little socket serverthat works (tested with telnet) and now I am starting to code myself a client ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    scanning a network

    I made a little socket serverthat works (tested with telnet) and now I am starting to code myself a client to interact with the server.

    The problem:

    multiple pc can host multiple servers with diffirent ports. The client will have to scan the network to search for servers and build a list of server where one is choosen at random.

    Now scanning the network (10.0.0.1 - 10.0.0.254) takes forever.

    Code:
    for(i = 1 ; i < 255  ; i++){
    		bzero(address,16);
    		sprintf(address,"%s%d",NETWORK,i);
    		serv_addr.sin_addr.s_addr = inet_addr(address);
    		for (y = MINPORT ; y <= MAXPORT ;y++){
    			serv_addr.sin_port = htons(y);
    			if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(struct sockaddr))  < 0){
    				if (DEBUG){printf("%s:%d no connection\n",address,y);}/*No server found*/
    				
    			}
    			else{
    				found++;
    				if (DEBUG){printf("w0000000000t %s:%d got connection\n",address,y);}
    				close(sockfd);
    				sockfd = socket(AF_INET, SOCK_STREAM, 0);	
    			}	
    		}
    	}
    }
    There has to be a better way to do this I hope. Please help.

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    it would be best to use raw sockets and send the connection attempt manually. The connect function can take forever to timeout. This isn't an easy thing to do, though there are plenty of open source things for linux that will do this. There is one in particular, but I can't quite remember the name. try doing a google search for something like "raw sockets syn packet"

  3. #3
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Hi

    Nmap is a powerful open source port scanner. I don't know but it may have a network scannig option.

    http://www.insecure.org/nmap/

    Hope helps...

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    I am now testing the raw sockets thing. Hope it works. Also I think I just might change my server to respond a broadcast and then sending his ip and port to the client that send the broardcast.

    Will see if nmap can help.

    Ty to you will let you know how it works out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D Network Analysis Tool
    By durban in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 11-08-2005, 06:33 PM
  2. Need help with easy Network setup
    By the dead tree in forum Tech Board
    Replies: 9
    Last Post: 04-08-2005, 08:44 PM
  3. network problems
    By lucy in forum Tech Board
    Replies: 6
    Last Post: 01-01-2003, 03:33 PM
  4. Got Network?
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 11-21-2002, 03:44 PM
  5. WinXP Network Connections pop-up
    By DavidP in forum Tech Board
    Replies: 1
    Last Post: 10-02-2002, 06:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21