DotNet Tutorials

Server Intellect

 Resolved hosting informat using ASP.NET 2.0 andC# .NET

This tutorial will show you how to resolved hosting information by typing in the DNS name using ASP.NET 2.0 and C# 2.0. This tutorial will show you how to resolved hosting information by typing in the DNS name using ASP.NET 2.0 and C#.NET.

First, you will need to import the System.Net namespace. The System.Net namespace provides a simple programming interface for many of the protocols used on networks today. The namespace contains the Classes IPHostEntry , IPAddress and DNS. The DNSclass is a static class that retrieves information about a specific host from the Internet Domain Name System (DNS). The host information from the DNS query is returned in an instance of the IPHostEntry class. If the specified host has more than one entry in the DNS database, IPHostEntry contains multiple IP addresses and aliases. The IPAddress class contains the address of a computer on an IP network. The IPHostEntry class associates a Domain Name System (DNS) host name with an array of aliases and an array of matching IP addresses.The IPHostEntry class is used as a helper class with the DNS class.

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!

using System.Net;

We use the btnResolve_Click event to do the work. We then call the Dns.Resolve to resolve the hosting information using the variables from our ASP.NET coded page

protected void btnResolve_Click(object sender, EventArgs e)
{
try
{
listIP.Items.Clear();
txtHostname.Text = "";
IPHostEntry iphost = Dns.Resolve(txtBoxinput.Text);
foreach(IPAddress ip in iphost.AddressList)
{
string ipaddress=ip.AddressFamily.ToString();
listIP.Items.Add(ipaddress);
listIP.Items.Add(" "+ip.ToString());
}
txtHostname.Text=iphost.HostName;
labmessage.Visible = false;
}
catch(Exception ex)
{
labmessage.Visible = true;
labmessage.Text="Unable to process the request because"+"<br/>"+"the following problem occurred:"+"<br/>"+ex.Message;
}
}

The front end .aspx page looks something like this:

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#eeeeee" class="header1">
<fieldset>
<legend>DnsLookup</legend>
<div>
<asp:Label ID="Label2" runat="server" Text="Type in the DNS name to be resolved;then click the Resolve button"
Width="227px"></asp:Label>
<asp:Button ID="btnResolve" runat="server" Text="Resolve" OnClick="btnResolve_Click" /><br />
<asp:TextBox ID="txtBoxinput" runat="server" Width="292px"></asp:TextBox>
<br />
<fieldset style="width: 232px">
<legend>Results</legend>
<asp:TextBox ID="txtHostname" runat="server" Width="286px"></asp:TextBox><br />
<asp:ListBox ID="listIP" runat="server" Height="185px" Width="292px"></asp:ListBox></fieldset>
<br />
<asp:Label ID="labmessage" runat="server" ForeColor="Red"></asp:Label></div>
</fieldset>
</td>
</tr>
</table>

The flow for the code behind page is as follows.

Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;

public partial class DnsLookupCsharp : System.Web.UI.Page
{
protected void btnResolve_Click(object sender, EventArgs e)
{
try
{
listIP.Items.Clear();
txtHostname.Text = "";
IPHostEntry iphost = Dns.Resolve(txtBoxinput.Text);
foreach(IPAddress ip in iphost.AddressList)
{
string ipaddress=ip.AddressFamily.ToString();
listIP.Items.Add(ipaddress);
listIP.Items.Add(" "+ip.ToString());
}
txtHostname.Text=iphost.HostName;
labmessage.Visible = false;
}
catch(Exception ex)
{
labmessage.Visible = true;
labmessage.Text="Unable to process the request because"+"<br/>"+"the following problem occurred:"+"<br/>"+ex.Message;
}
}
}



Looking for the VB.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect