Monday, October 29, 2012

How to Get IP Address of our own Machine..


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

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

IPAddress[] addr = ipEntry.AddressList;

string ip= addr[addr.Length - 1].ToString();


If you want to Retrive True IP Address then


string IPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (IPAddress == null) //may be the HTTP_X_FORWARDED_FOR is null
{
            IPAddress = Request.ServerVariables["REMOTE_ADDR"];//we can use REMOTE_ADDR
}



0 comments:

Post a Comment