Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Network - Resolved hosting informat using ASP.NET 2.0 and VB .NET
Resolved hosting informat using ASP.NET 2.0 and VB .NET


ASP.NET Network Tutorial

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.

Untitled Document

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

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 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.

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

Download the Full Working Version of this Project written with Visual Studio.NET VB 2005 Here!

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!







 
  Developer Resources







Server Intellect Rocks