How to get the User IP Address?

vishalneeraj-24503
Posted by vishalneeraj-24503 under C# category on | Points: 40 | Views : 2463
It's very easy to get IP address,we have to import System.Net namespace to get IP addresses.

private string local_IP_Address()
{
string local_IP_address = string.Empty;

try
{
System.Net.IPHostEntry host;

host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
foreach (System.Net.IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
local_IP_address = ip.ToString();
break;
}
}
}
catch (Exception ex)
{
throw ex;
}
return local_IP_address;
}

Comments or Responses

Login to post response