ASP.NET - Tracking IP and O.S OF VISITOR

Asked By poonam jaiswal
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
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
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
10-Feb-12 07:00 AM
pls also tell me how to track O.S. of visitor
Create New Account
help
NetworkInformation; using System.Collections.Generic; using System.Net.Sockets; namespace IPLookup { class MainClass { public static IPAddress[] GetAllUnicastAddresses_Old() { / / By passing an empty string to GetHostEntry we receive all the IP addresses on the local machine / / This breaks on Mono IPHostEntry LocalEntry = Dns.GetHostEntry(""); return LocalEntry.AddressList; } public static IPAddress[] GetAllUnicastAddresses_New() { / / This works on both Mono and .NET , but there is a difference: it also / / includes the LocalLoopBack so we need to filter that one out List<IPAddress> Addresses = new List<IPAddress> (); / / Obtain a reference to all network interfaces in the machine NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach properties = adapter.GetIPProperties(); foreach (IPAddressInformation uniCast in properties.UnicastAddresses) { / / Ignore loop-back addresses & IPv6 if (!IPAddress.IsLoopback(uniCast.Address) && uniCast.Address.AddressFamily! = AddressFamily.InterNetworkV6) Addresses.Add(uniCast.Address); } } return Addresses.ToArray
ipaddress using v6 So I am using a TCPClient application that sits and listens for a client to connect to it. So therefore I need the ipAddress of the users machine. I am running into an issue with a user having an array list Private Function GetIP() As String Dim strHostName As String = "" strHostName = System.Net. Dns .GetHostName() Dim ipEntry As IPHostEntry = System.Net. Dns .GetHostEntry(strHostName) Dim addr As IPAddress () = ipEntry.AddressList Return addr(addr.Length - 1).ToString() End Function This errors out on my As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim hostname As IPHostEntry = Dns.GetHostByName(TextBox1.Text) Dim ip As IPAddress() = hostname.AddressList TextBox2.Text = ip(0).ToString() End Sub End Class http: / / www.dreamincode.net
Window Application How to get IPAddress in Window application / / Get the hostname string myHost = System.Net. Dns .GetHostName(); / / Show the hostname MessageBox .Show(myHost); / / Get the IP from the host name string myIP 0].ToString(); / / Show the IP MessageBox .Show(myIP); public static string mGetIPAddress() { string strHostName = Dns .GetHostName(); string strIPAddress = "" ; IPHostEntry iphostentry = Dns .GetHostEntry(strHostName); foreach ( IPAddress ipaddress in iphostentry.AddressList) { strIPAddress = ipaddress.ToString(); } return strIPAddress; } using System.Management; / / Query for all the
string strHost; Console.Write( "Input host : " ); / / Iput web host name as string strHost = Console.ReadLine(); IPHostEntry IPHost = Dns.Resolve(strHost); / / though Dns to get IP host Console.WriteLine(IPHost.HostName); / / Output name of web host IPAddress [] address = IPHost.AddressList; / / get list of IP address Console.WriteLine( "List IP {0} :" , IPHost.HostName User:" + user.ToString()); Response.Write( "< / br> " + Environment .UserName.ToString()); Response.Write( "< / br> " + System.Security.Principal. WindowsIdentity .GetCurrent().Name.ToString()); } Hi Following code will help u for getting IP address. . . . First you System.Net; Example of code to get address from hostname: [C#] try { string hostName = Dns.GetHostName(); IPHostEntry iPHostEntry = Dns.GetHostEntry(hostName); IPAddress[] ipAddress = iPHostEntry.AddressList; for (int i = 0; i < ipAddress.Length; i++) { Response.Write(ipAddress[i