Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Sniff Web Clients using ASP.NET

0.00/5 (No votes)
14 Apr 2003 1  
Using .NET Framework web classes one can sniff lots of information from the web clients.

Introduction

This article is about how to sniff web clients using ASP.NET. One can sniff lots of information from the clients using the web classes of the .NET Framework. Well, for those who want to know what is web sniff, it's basically extracting client and browser information. Now the question is why somebody has to sniff the client information? Well, there are two dimensions to this question: one is data capturing for administration, back office and security purposes, which helps us to do some survey like what kind of browsers are connected more, what types of software clients are used more etc.. The second perspective is for developers to know what browser it is and what type of technologies it can support so that the developers can write dynamic web pages depending on the type of the client one connects to. For example, if somebody is connected using Internet Explorer (IE) he can send dynamic HTML pages with VBScript as the client-side script. And if it�s Netscape Navigator he can push dynamic HTML pages with JavaScript as the client-side script. Developers can also check what kind of HTML version the client browser supports etc..

In the .NET Framework, under the System.Web namespace, we have a class HttpBrowserCapabilities. This class helps us to gather information on the capabilities of the browser that is running on the client. Apart from this class, we have a HttpRequest class collection property named ServerVariable. This collection helps to get the complete request header and some client information. In the sample program, I have used both the classes for getting maximum information from the clients. Below is the output of the web sniff ASP.NET program.

I have used C# language for the sample program in ASP.NET. Below is the ASP.NET code Snippet:

<% 
HttpBrowserCapabilities browserObj; 
browserObj = Request.Browser; 
%> 
Client Name:<%=Request.ServerVariables["REMOTE_HOST"]%> 
Client IP Address: <%=Request.ServerVariables["REMOTE_ADDR"]%> 
Platform: <%=browserObj.Platform%> 
Browser String: <%=Request.ServerVariables["http_user_agent"]%> 
Browser Language: <%=Request.ServerVariables["http_accept_language"]%> 
Browser type: <%=browserObj.Type %> 
Browser version: <%=browserObj.Version%> 
Browser Beta: <%=browserObj.Beta%> 
Client CLR Version: <%=browserObj.ClrVersion%> 
Supports ActiveX controls: <%=browserObj.ActiveXControls %> 
Supports Cookies: <%=browserObj.Cookies%> 
Supports Frames: <%=browserObj.Frames%> 
Supports HTML Tables: <%=browserObj.Tables%> 
Supports Java Applets: <%=browserObj.JavaApplets%> 
Supports Java Scripts: <%=browserObj.JavaScript%> 
Supports MS DOM Version: <%=browserObj.MSDomVersion%>

In the class HttpRequest (System.Web namespace), the Browser property returns the HttpBrowserCapabilities class. Using this class, we can get lots of information about the client. The members of the HttpBrowserCapabilties class like Type, Version, Beta, ClrVersion etc.. gives client information. Some of the properties of the HttpBrowserCapabilities class which are used in this sample program are given below:

  • ActiveXControls

    Gets a boolean value indicating whether the client browser supports ActiveX controls.

  • Beta

    Gets a boolean value indicating whether the browser is a beta release.

  • Browser

    Gets the browser string (if any) that was transmitted in the User-Agent header.

  • Clrverson

    Gets the version number of the .NET common language runtime installed on the client.

  • Cookies

    Gets a boolean value indicating whether the client browser supports cookies.

  • Frames

    Gets a boolean value indicating whether the client browser supports HTML frames.

  • JavaApplets

    Gets a boolean value indicating whether the client browser supports Java applets.

  • JavaScript

    Gets a Boolean value indicating whether the client browser supports JavaScript.

  • MSDomVersion

    Gets the version of Microsoft Document Object Model (DOM) that the client browser supports.

  • Platform

    Gets the name of the platform that the client uses.

  • Tables

    Gets a boolean value indicating whether the client browser supports HTML tables.

  • Type

    Gets name and major version number of the client browser.

  • VBScript

    Gets a boolean value indicating whether the client browser supports VBScript.

  • Version

    Gets the full (integer and decimal) version number of the client browser.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here