Getting IP Address of client machine.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 638
private string GetIP()
{
string IpAddress = string.empty;
1st method:-
string HostName = string.empty;
HostName = System.Net.Dns.GetHostName();
IpAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(1).ToString();

2nd method:-
string IpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (IpAddress == null)
{
IpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
return IpAddress;
}

Comments or Responses

Login to post response