Click here to Skip to main content
11,573,618 members (46,825 online)
Click here to Skip to main content

Web Server Information using .NET

, 30 Aug 2010 CPOL 17.2K 732 25
Rate this:
Please Sign up or sign in to vote.
This articles explains about a tool which can be used to get web server information using WebClient in .NET
webinfo.jpg

Introduction

This article is about a tool which you can use to get information like encoding, cookie details, web server name, server language, their version numbers, etc.

Are They Accurate?

We cannot guarantee as it is possible for the server guys to fake/disable parameters if they wish.

About WebClient

WebClient belongs to System.Net.WebClient. You can find the MSDN page here.

WebClient provides common methods for sending data to and receiving data from a resource identified by a URI.

This feature is available from .NET Framework version 2.0. I have made use of this feature for building this handy tool.

Using the Code

This is the heart code of this tool which gets data from the server and displays the parameters to a textbox.

WebClient wc = new WebClient();
// This line adds a user agent string to header of Web Client.
// user agent is optional but some websites/servers use this string
// to verify whether you are a bot or browser. We use this to act our tool 
// like a browser.
// More info about user agent here - http://en.wikipedia.org/wiki/User_agent

wc.Headers.Add("user-agent", "Mozilla/4.0 
	(compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); 

// Below line reads information from the server of specified website.
// OpenRead() method returns the contents of the file, but since we do not need
// it for our tool, I am not reading it to a variable.
wc.OpenRead(site); 

// wc.ResponseHeaders contents all the header responses from server.
// I am adding those information to a StringBuilder variable with some formatting.
// wc.ResponseHeaders.Count returns number of keys/values available. 
// Count varies from website to website
for (int i = 0; i < wc.ResponseHeaders.Count; i++)
{
     sb.Append((i + 1).ToString() + ". [" + wc.ResponseHeaders.AllKeys[i] + "] => " 
     + wc.ResponseHeaders[i] + Environment.NewLine + Environment.NewLine);
}

// Finally, the formatted string is passed to the multi-line textbox
textBox1.Text = sb.ToString();

WebClient.ResponseHeaders is the property which brings our necessary parameters from the server.

Who Can Benefit from this Tool?

Well, technology enthusiasts, I would say. If somebody is interested to know which website runs on which server/language, then this tool is for them.

Some of my observations with this tool here:

  • google.com - gws (Google Web Server)
  • codeproject.com - IIS6, ASP.NET 4.0
  • microsoft.com - IIS 7.5/ASP.NET 4.0
  • msdn - IIS 7.5/ASP.NET 2.0
  • php.net - Apache 1.3/PHP 5.2
  • apache.org - Apache 2.3
  • python.org - Apache 2.3/Python 2.5
  • gmail - GSE (Google Search Extension)
  • oracle.com - Oracle Application Server
  • java.com - Sun Java System Web Server
  • wikipedia.org - Apache

History

  • Monday, 30 August 2010 - Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Praveen Nair (NinethSense)
Architect ORION INDIA SYSTEMS
India India
Praveen.V.Nair - aka NinethSense - PMP, Microsoft MVP - is working as a Head of Technology and Architecture at Orion India Systems, Kochi, India. He has been playing with electronics from the age of 10 and with computers from the age of 14. He usually blogs at http://blog.ninethsense.com/.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 2 [modified] Pin
roybrew7-Sep-10 3:06
memberroybrew7-Sep-10 3:06 
GeneralRe: My vote of 2 Pin
NinethSense7-Sep-10 22:04
memberNinethSense7-Sep-10 22:04 
GeneralRe: My vote of 2 Pin
roybrew8-Sep-10 2:46
memberroybrew8-Sep-10 2:46 
GeneralRe: My vote of 2 Pin
NinethSense8-Sep-10 3:04
memberNinethSense8-Sep-10 3:04 
GeneralRe: My vote of 2 Pin
roybrew8-Sep-10 3:15
memberroybrew8-Sep-10 3:15 
Generalnice one Pin
rondevis30-Aug-10 22:36
memberrondevis30-Aug-10 22:36 
GeneralRe: nice one Pin
NinethSense30-Aug-10 23:58
memberNinethSense30-Aug-10 23:58 
GeneralMy vote of 3 Pin
karabax30-Aug-10 6:36
memberkarabax30-Aug-10 6:36 
GeneralRe: My vote of 3 Pin
NinethSense30-Aug-10 18:05
memberNinethSense30-Aug-10 18:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 31 Aug 2010
Article Copyright 2010 by Praveen Nair (NinethSense)
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid