[.Net]取得目前的IP

  • 171
  • 0

[.Net]取得目前的IP

取得目前的IP:
 

//取得目前IP
private string GetLocalIPAddress()
{
	var host = Dns.GetHostEntry(Dns.GetHostName());
	foreach (var ip in host.AddressList)
	{
		if (ip.AddressFamily == AddressFamily.InterNetwork)
		{
			return ip.ToString();
		}
	}
	throw new Exception("Local IP Address Not Found!");
}