Get IP Address

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 610
public void GetIPAddress()
{
1st method:-
string HostName = String.Empty;
HostName = System.Net.Dns.GetHostName();
Response.Write(System.Net.Dns.GetHostAddresses(HostName).GetValue(1).ToString());

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

Comments or Responses

Login to post response