ASP.NET - Tracking IP and O.S OF VISITOR - Asked By poonam jaiswal on 10-Feb-12 05:56 AM

I am doing a project of live support chat. i want to know how to track information of visitors like IP , O.S. etc using cookies .
Web Star replied to poonam jaiswal on 10-Feb-12 06:02 AM
use the following code to get ip address using DNS settin

Private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();

IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

IPAddress[] addr = ipEntry.AddressList;

return addr[addr.Length-1].ToString();

}

The IP Address can be retreived in the following ways.

String str = HttpContext.Current.Request.UserHostAddress;

or

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

The REMOTE_ADDR usually provides the IP Address of the Internet Service Provider in some cases.As a result it may be required to test with HTTP_X_FORWARDED_FOR to get the real IP Address.This might also contain an array of IP addresses when connected through proxies.

Eg : Request.ServerVariables(”HTTP_X_FORWARDED_FOR”);

and check to see if it returns an Empty and then retreive the corresponding IP Address using REMOTE_ADDR.

dipa ahuja replied to poonam jaiswal on 10-Feb-12 06:07 AM
void getClientInfo()
{
  string RemoteIp = Request.UserHostAddress.ToString();
  string DNSName = Request.UserHostName;
  string user = HttpContext.Current.Request.UserHostAddress;
 
  Response.Write("</br>Remote Ip:" + RemoteIp);
  Response.Write("</br>DNS Name :" + RemoteIp);
  Response.Write("</br>" + Environment.MachineName.ToString());
  Response.Write("</br>  User:" + user.ToString());
 
  Response.Write("</br>" + Environment.UserName.ToString());
  Response.Write("</br>" + System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
}
 
poonam jaiswal replied to Web Star on 10-Feb-12 07:00 AM
pls also tell me how to track O.S. of visitor