.Net通过域名获取服务器IP地址


C#通过域名即可获取服务器IP地址


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;

namespace AutoHome.Net
{
    public partial class GetIP : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //.通过域名获取服务器IP地址
            IPAddress[] IPs = Dns.GetHostAddresses("www.baidu.com");
            foreach (IPAddress ip in IPs)
            {
                Response.Write(ip.ToString() + "<br>");
            }
        }
    }
}