title: Fastest Way to scan for Open port in network
body: <p>How can I scan for a given port number say (8000) in the network?<br>
  i tried it using general sockets tcp connection. though it works it takes lot of time time if number of alive ip is more than 15.Goal is to get the list of ip from the network whose given port is open.<br>
  This is how i get the list of IP from my network </p>
  
  <pre><code>    std::vector&lt;std::string&gt; resultIPList;
      FILE* pipe = popen("arp-scan --localnet","r");
      if(!pipe)
      {
          fprintf(stderr,"Unable to open pipe");
          return resultIPList;
      }
      char buffer[128];
      while(!feof(pipe))
      {
          if(fgets(buffer, 128, pipe) != NULL)
          {
              stringBuffer += buffer;
          }
      }
      pclose(pipe);
  </code></pre>
  
  <p>Now My stringBuffer has the ip list. i Have written a parser which extracts ip from the string and give me a vector of those ip. Now i will scan each of them one by one for given port.The function below is for windows, in linux i am doing same using boost::asio</p>
  
  <pre><code>    struct sockaddr_in client;
      int sock;  
      client.sin_family      = AF_INET;
      client.sin_port        = htons(portNo);
      client.sin_addr.s_addr = inet_addr( Ip.c_str() );
      sock = (int) socket(AF_INET, SOCK_STREAM, 0);
      return (::connect(sock, (struct sockaddr *) &amp;client,sizeof(client)) == 0);
  </code></pre>