Q

How do we know the server running on another machine is Apache or IIS?

How do we know the server running on another machine is Apache or IIS?

Well if you are really lucky, the following method will return the server name and version in a form something like:

   Server: Microsoft-IIS/5.0

However, this is not as straight-forward as it may seem. First of all, if the site is running a caching Web proxy, you might be connecting to the Web proxy rather than the Web server, which can return invalid results. If the site is using a load balancer, you might also get invalid results. If the site is using a TCP firewall, you could get a response from the firewall machine rather than the Web server, again with invalid results.

   void getServerInfo(String aURL)
   {
      BufferedReader   reader;
      URL              url = new URL(aURL);
      String           host = url.getHost();
      int              port = url.getPort();
      if (port == -1)
         port = 80;
      String           file = url.getFile();
      Socket           socket = new Socket(host, port);
      Writer           writer = new
OutputStreamWriter(socket.getOutputStream());
      Reader           inReader = new
InputStreamReader(socket.getInputStream());
      BufferedReader   bufReader = new BufferedReader(inReader);

      try {
         writer.write("GET " + file + " HTTP/1.0\r\n\n");
         writer.flush();
         String input;
         while ((input = bufReader.readLine()) != null)
         {
            System.out.println(input);
         }
      }
      catch(Exception e)
      {
         System.out.println(e.toString());
      }
      finally
      {
         reader.close();
      }
   }

This was first published in September 2002

Dig deeper on SOA, XML and Web Services Development Tools

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close