DotNet Tutorials

Server Intellect

 Resolved hosting informat using ASP.NET 2.0 and VB .NET

This tutorial will show you how to resolved hosting information by typing in the DNS name using ASP.NET 2.0 and VB 2.0. This tutorial will show you how to resolved hosting information by typing in the DNS name using ASP.NET 2.0 and VB.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.

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

Imports 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 Sub btnResolve_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
listIP.Items.Clear()
txtHostname.Text = ""
Dim iphost As IPHostEntry = Dns.Resolve(txtBoxinput.Text)
Dim ip As IPAddress
For Each ip In iphost.AddressList
Dim ipaddress As String = ip.AddressFamily.ToString()
listIP.Items.Add(ipaddress)
listIP.Items.Add((" " + ip.ToString()))
Next ip
txtHostname.Text = iphost.HostName
labmessage.Visible = False
Catch ex As Exception
labmessage.Visible = True
labmessage.Text = "Unable to process the request because" + "<br/>" + "the following problem occurred:" + "<br/>" + ex.Message
End Try
End Sub

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.

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

Imports System.Net

Partial Class DnsLookupVB
Inherits System.Web.UI.Page

Protected Sub btnResolve_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
listIP.Items.Clear()
txtHostname.Text = ""
Dim iphost As IPHostEntry = Dns.Resolve(txtBoxinput.Text)
Dim ip As IPAddress
For Each ip In iphost.AddressList
Dim ipaddress As String = ip.AddressFamily.ToString()
listIP.Items.Add(ipaddress)
listIP.Items.Add((" " + ip.ToString()))
Next ip
txtHostname.Text = iphost.HostName
labmessage.Visible = False
Catch ex As Exception
labmessage.Visible = True
labmessage.Text = "Unable to process the request because" + "<br/>" + "the following problem occurred:" + "<br/>" + ex.Message
End Try
End Sub
End Class



Looking for the C#.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