DNS类.internet域名系统是网络应用程序获取网络上主机信息的常规系统. 主机的信息包括主机名,域名,ip地址. DNS方法总是以IPJostEntry对象的形式返回信息. cs代码: using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Net;namespace ASPNETWORK...{ /**//// <summary> /// WebForm1 的摘要说明。 /// </summary> public partial class WebForm1 : System.Web.UI.Page ...{ protected void Page_Load(object sender, System.EventArgs e) ...{ lbHost.Text = Dns.GetHostName(); IPHostEntry Host = Dns.GetHostByName(lbHost.Text); lbHost.Text = "本机域名为:"+lbHost.Text+"IP地址为:"+Host.AddressList[0].ToString(); } Web Form Designer generated code#region Web Form Designer generated code override protected void OnInit(EventArgs e) ...{ // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /**//// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() ...{ } #endregion protected void btnGetIP_Click(object sender, System.EventArgs e) ...{ try ...{ IPHostEntry Host = Dns.GetHostByName(tbDomain.Text); lbIP.Text = Host.AddressList[0].ToString(); } catch(Exception ex) ...{ lbIP.Text = ex.Message.ToString(); } } protected void getDomain_Click(object sender, System.EventArgs e) ...{ try ...{ IPHostEntry Host = Dns.GetHostByAddress(tbIP.Text); lbDomain.Text = Host.HostName; } catch(Exception ex) ...{ lbDomain.Text = ex.Message.ToString(); } } }} html代码: <%...@ Page language="c#" Inherits="ASPNETWORK.WebForm1" CodeFile="01DNS.aspx.cs" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body> <form id="Form1" method="post" runat="server"> <asp:Label id="Label1" style="Z-INDEX: 100; LEFT: 242px; POSITION: absolute; TOP: 53px" runat="server" Width="224px" Font-Size="XX-Large">DNS示例</asp:Label> <asp:Label id="lbDomain" style="Z-INDEX: 113; LEFT: 571px; POSITION: absolute; TOP: 238px" runat="server" Width="136px"></asp:Label> <asp:Button id="getDomain" style="Z-INDEX: 112; LEFT: 484px; POSITION: absolute; TOP: 236px" runat="server" Text="得到域名" onclick="getDomain_Click"></asp:Button> <asp:TextBox id="tbIP" style="Z-INDEX: 111; LEFT: 297px; POSITION: absolute; TOP: 237px" runat="server"></asp:TextBox> <asp:Label id="Label4" style="Z-INDEX: 110; LEFT: 165px; POSITION: absolute; TOP: 243px" runat="server">请输入IP:</asp:Label> <asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 296px; POSITION: absolute; TOP: 191px" runat="server"></asp:TextBox> <asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 484px; POSITION: absolute; TOP: 191px" runat="server" Text="得到IP"></asp:Button> <asp:Label id="lbHost" style="Z-INDEX: 101; LEFT: 157px; POSITION: absolute; TOP: 136px" runat="server" Width="459px"></asp:Label> <asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 162px; POSITION: absolute; TOP: 195px" runat="server">请输入域名:</asp:Label> <asp:TextBox id="tbDomain" style="Z-INDEX: 104; LEFT: 296px; POSITION: absolute; TOP: 191px" runat="server"></asp:TextBox> <asp:Button id="btnGetIP" style="Z-INDEX: 106; LEFT: 484px; POSITION: absolute; TOP: 191px" runat="server" Text="得到IP" onclick="btnGetIP_Click"></asp:Button> <asp:Label id="lbIP" style="Z-INDEX: 109; LEFT: 574px; POSITION: absolute; TOP: 195px" runat="server" Width="136px"></asp:Label> </form> </body></HTML>