网络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;
        }
    }
}

 

运行界面:

 网络DNS域名转换成IP地址

相关文章:

  • 2022-12-23
  • 2021-07-04
  • 2021-06-01
  • 2021-06-19
  • 2021-05-22
猜你喜欢
  • 2022-12-23
  • 2022-02-15
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
相关资源
相似解决方案