网络DNS域名转换成IP地址(完整代码,测试通过)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace DNS2IP
{
class Program
{
//主函数,入口函数
static void Main(string[] args)
{
string strDNS="www.google.com";
string strIP = GetIP(strDNS);
Console.WriteLine(strIP);
Console.ReadLine();
}
// 利用域名,获取IP地址
public static string GetIP(string strDNS)
{
IPHostEntry hostEntry = Dns.GetHostEntry(strDNS);
IPEndPoint ipEndPoint = new IPEndPoint(hostEntry.AddressList[0], 0);
string ipAddress = ipEndPoint.Address.ToString();
return ipAddress;
}
}
}
运行界面:
<!--StartFragment -->
本文提供了一个简单的C#程序示例,用于将网络DNS域名转换为对应的IP地址。该程序使用了.NET Framework中的System.Net命名空间,并通过Dns.GetHostEntry方法获取主机条目,进而得到IP地址。
1072

被折叠的 条评论
为什么被折叠?



