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.
| using System.Net; |
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
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; |
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 front end .aspx page looks something like this:
| <table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc"> <tr> </table> <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> |
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.
The flow for the code behind page is as follows.
| 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; |
No comments:
Post a Comment