Translate

Thursday, 18 June 2015

get ip address in c#

 //using System.Net;
        string hostName = Dns.GetHostName(); // Retrive the Name of HOST  
        string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();
        Response.Write("My IP Address is :" + myIP);



or
-------
string ip_address = Convert.ToString(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
   Response.Write("My IP Address is :" + ip_address);  

No comments:

Post a Comment