title: C/UNIX: port scanner
body: <p>I need program that find all web servers into file that contains IP addresses.
  I found that IP address is server if his port 80 is open. And I wrote this code but it doesn't work. Аlways sayd that port 80 is closed, even i write IP with open port 80. (194.153.145.104 for example). Where I wrong? 
  I'm cheking here for IP's with open ports: <a href="http://www.yougetsignal.com/tools/open-ports/" rel="nofollow">http://www.yougetsignal.com/tools/open-ports/</a></p>
  
  <pre><code>#include &lt;sys/socket.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char *argv[])
  {
  
  u_short port=80;            /* user specified port number */
  short int sock = -1;        /* the socket descriptor */
  struct hostent *host_info;  /* host info structure */
  struct sockaddr_in address; /* address structures */
  char addr[1023];
  char buf[20];
  char *filename;
  
  filename=argv[1];
  
  FILE *file = fopen( filename, "r" );
  
      while (!feof(file))
      {
      fscanf(file,"%s",buf);
      strncpy(addr, buf, 1023);
  
  
      bzero((char *)&amp;address, sizeof(address));
      address.sin_addr.s_addr = inet_addr(addr);
      address.sin_port = htons(port);      
      address.sin_family=AF_INET;
  
      sock = socket(PF_INET, SOCK_STREAM, 0);
      if (sock == -1) {
          fprintf(stderr, "Error: could not assign master socket\n");
          exit (1);
      }
      if(connect(sock,(struct sockaddr *)&amp;address,sizeof(address)) == 0)
          printf("%s is a web server\n", addr);
  
      else printf("%s isn't a web server\n", addr);
  
      close(sock);
  
      }
  
      return 0;
      }
  </code></pre>