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


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


01using System;
02using System.Collections.Generic;
03using System.Linq;
04using System.Web;
05using System.Web.UI;
06using System.Web.UI.WebControls;
07using System.Net;
08 
09namespace AutoHome.Net
10{
11    public partial class GetIP : System.Web.UI.Page
12    {
13        protected void Page_Load(object sender, EventArgs e)
14        {
15            //.通过域名获取服务器IP地址
16            IPAddress[] IPs = Dns.GetHostAddresses("www.baidu.com");
17            foreach (IPAddress ip in IPs)
18            {
19                Response.Write(ip.ToString() + "<br>");
20            }
21        }
22    }
23}