网络DNS域名转换成IP地址

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

 

运行界面:

 

posted @ 2010-01-07 15:12  SpringMVC+Hibernate  阅读(262)  评论(0编辑  收藏  举报
友情链接:厦门事业单位