2024-11-07 14:20:54
1、引用命名空间:
using System.Net;
2、通过域名获取IP,并打印到控制台:
class Program
{
static void Main(string[] args)
{
IPAddress[] IPs = Dns.GetHostAddresses("www.baidu.com");
foreach (IPAddress ip in IPs)
{
Console.WriteLine(ip);
}
Console.ReadKey();
}
}