DNS lookup for a particular Fully Qualified Domain Name : Dns « Network « ASP.Net






DNS lookup for a particular Fully Qualified Domain Name


<%@ Page Language="c#" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<html>
  <title>Performing a DNS Lookup </title>
  <head>
    <script language="c#" runat="server">
       void BtnCheck_Click(Object sender,EventArgs e) {
        try
        {
            LblHostName.Text = "";
            IPHostEntry GetIPHost = Dns.GetHostByName(TxtInput.Text);
            LblValue.Text = "DNS LookUp as : " + "<Br>";
            foreach(IPAddress ip in GetIPHost.AddressList)
            {
              long HostIpaddress = ip.Address;
              LblValue.Text += HostIpaddress.ToString() + " -- ";
              LblValue.Text += ip.ToString() + "<Br>";
              
            }
            LblHostName.Text = "Host Name is: "  + GetIPHost.HostName;
        }catch(Exception ex){
          LblValue.Text = "<font color=red>Error:" + ex.Message;
        }
       }

    </script>
  </head>
  <body>
    <h3><font face="Verdana">DNS lookup for a particular Fully Qualified Domain Name.</font></h3>
    <form runat="server">
      Please enter Fully qualified Domain name:
      <asp:TextBox id="TxtInput" runat="server" value="www.google.com" /><br />
      <asp:Button id="BtnCheck" Text="Click Me" onclick="BtnCheck_Click" runat="server" /><br />
      <br />
      <asp:Label id="LblValue" runat="server" /><br />
      <asp:Label id="LblHostName" runat="server" />
    </form>
  </body>
</html>

 








Related examples in the same category

1.Performing a Reverse-DNS Lookup