Monday, 25 July 2011

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.

Imports System.Net

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

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

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

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>

We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.

The flow for the code behind page is as follows.

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!

No comments:

Post a Comment