在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地址。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:C#获取IP地址的性能优化技巧是什么