Home | Contact Us | Download | Support | Purchase | Products

Product List
  "Thanks - love these components!"
D. Oakland


The following article will describe how to use aspNetPing from Visual Studio .NET using C#. This brief tutorial assumes you have IIS installed locally on your machine, and have downloaded and installed aspNetPing from www.aspNetPing.com . For an updated version of this article, visit www.aspNetPing.com/examples.aspx 

Using Visual Studio .NET (VS.NET ) You will create a single webform (lookup.aspx) that allows users to perform a Pointer (Reverse Lookup ) of an IP address.. Lookup.aspx will use aspNetDns to perform the reverse lookup.

1. Launch Visual Studio .NET

2. From the main menu, select the File | New | Project command.

3. The New Project dialog box appears. Under Project Types, Select Visual Basic Projects. Under Templates, select ASP.NET Web Application. In the Location textbox, enter http://localhost/aspNetPingTest


Setting the Reference to aspNetPing.

1. In the Solution Explorer, right-click the project name, aspNetPingTest, and select the Add | Add Existing Item command.

2. The Add Existing Item dialog box appears. Under Files of Type, select All Files(*.*). Navigate to the directory you downloaded the aspNetDns.dll too. Double-click the aspNetDns.dll. The Add Existing Item dialog box closes, and the aspNetDns.dll was imported to the root directory of your project.

3. In the Solution Explorer, right-click the project name aspNetPingTest and select Add Reference. The Add Reference dialog box appears. Click the Browse button. The Select Component dialog box appears. Double-click the aspNetDns.dll file. The Select Component dialog box closes. Click OK. The Add Reference dialog box closes, and a reference is set to aspNetPing.

Create a Test Page.
Now that we have a reference set, let's create pingme.aspx to use aspNetPing.

1. In the Solution Explorer, right-click the project name aspNetPingTest, and select Add | Add Webform. The Add New Item dialog box appears. In the Name textbox, enter, pingme.aspx.

2. pingme.aspx loads in the designer window. Select the View | Html Source menu command. The html code of pingme.aspx appears. Between the opening and closing form tags add the following html

<INPUT id=txtHost type=text runat="server" NAME="txtHost"><INPUT type=submit value=Ping ID="Submit1" NAME="Submit1">
<PRE><asp:Literal id=PingResults Runat="server"></asp:Literal></PRE>

 This code will create a html text box, a submit button, and a <asp:literal> tag that we will use for writing out our results.

3. In the Solution Explorer, right-click pingme.aspx, and select View Code.

4. Add the following Imports statement to the top of the page.

	Imports aspNetPing

5. Be sure the following two lines of code to wire up the TextBox and <asp:Literal> are available at the class level.

	Protected WithEvents PingResults As System.Web.UI.WebControls.Literal 
        Protected WithEvents txtHost As System.Web.UI.HtmlControls.HtmlInputText

6. To the Page_Load method, add the following code.

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     If Page.IsPostBack Then
         Dim hostToPing As String = txtHost.Value
         Dim reply As ReplyPacketCollection = IcmpClient.Ping(hostToPing, 4)
         PingResults.Text = reply.ToString()
     End If
End Sub

This code first checks to see if the page was posted.  If the page was posted, the host is pinged the static method IcmpClient.Ping. The results are written to the literal tag by calling Reply.ToString(). ToString() specifically formats the ping results.

Testing The Page
Lets compile and test the page.

1. In the Solution Explorer, right-click the project name, aspNetPingTest, and select Build. The project will be compiled.

2. In the Solution Explorer, right-click pingme.aspx and select View in Browser.

3. Enter an IP or a host (such as www.yahoo.com )the textbox. Click Pingand aspNetPing will ping the host.   You should see similar results to those below:


EchoReply from seq: 1 bytes=32 time=81ms TTL=49
EchoReply from seq: 2 bytes=32 time=90ms TTL=49
EchoReply from seq: 3 bytes=32 time=90ms TTL=49
EchoReply from seq: 4 bytes=32 time=90ms TTL=49

Ping statistics for:
	Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
	Minimum = 81ms, Maximum = 90ms, Average = 87ms

That's all there is to using aspNetDns from Visual Studio .NET. In these few simple steps you were able to create a project, set a reference to aspNetDns, and ping an IP address. For more questions or comments, feel free to write support@advancedIntellect.com

Complete Source Code Listing
The entire source listing can be found here.

The box is not shipped. aspNetPing is a downloadable product.