在C#中獲取IP地址的步驟如下:
using System.Net;
string hostName = Dns.GetHostName();
IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
IPAddress[] ipAddressList = hostEntry.AddressList;
foreach (IPAddress ipAddress in ipAddressList)
{
Console.WriteLine(ipAddress.ToString());
}
通過以上步驟,就能夠在C#中獲取本地主機的IP地址。