Q
Problem solve Get help with specific problems with your technologies, process and projects.

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

Dig Deeper on Topics Archive

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.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchSoftwareQuality

SearchAWS

SearchCloudComputing

TheServerSide.com

Close