DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 Pinging using ASP.NET 2.0 and VB .NET

This tutorial will show you how to ping a hostname/ip using the .NET System.Net class, ASP.NET 2.0 and VB.NET

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

The .NET Framework offers a number of types that makes accessing resources on the network easy to use.

To perform a simple ping, we will need to use the System.Net, System.Net.Network.Information, System.Text namespaces.

imports System.Net;
imports System.Net.NetworkInformation;
imports System.Text;

We'll put our code in the btnSubmit_Click() event.

When the btnSubmit_Click() event fires it creates a new Ping object. We can then execute the Send method of this object to send a ping to the host specified in our text box. Executing this method also returns a PingReply object which we can use to gather information such as the Address, Roundtrip Time, TTL, and Buffer Size.

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
lblStatus.Text = ""
Dim ping As Ping = New Ping()
Dim pingreply As PingReply = ping.Send(txtHost.Text)
txtPing.Text &= "Address: " & pingreply.Address.ToString() & Constants.vbCr
txtPing.Text &= "Roundtrip Time: " & pingreply.RoundtripTime & Constants.vbCr
txtPing.Text &= "TTL (Time To Live): " & pingreply.Options.Ttl & Constants.vbCr
txtPing.Text &= "Buffer Size: " & pingreply.Buffer.Length.ToString() & Constants.vbCr

Catch err As Exception
lblStatus.Text = err.Message
End Try

The front end .aspx page looks something like this:

Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
<tr>
<td width="100" align="right" bgcolor="#eeeeee" class="header1">Hostname/IP:</td>
<td align="center" bgcolor="#FFFFFF">
<asp:TextBox ID="txtHost" runat="server"></asp:TextBox>
&nbsp;&nbsp;
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" /></td>
</tr>
<tr>
<td width="100" align="right" bgcolor="#eeeeee" class="header1">Ping Results:</td>
<td align="center" bgcolor="#FFFFFF">
<asp:TextBox ID="txtPing" runat="server" Height="66px" TextMode="MultiLine" Width="226px"></asp:TextBox>&nbsp;<br />
<asp:label ID="lblStatus" runat="server"></asp:label></td>
</tr>
</table>

The flow for the code behind page is as follows:

Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Text
Partial Public Class _Default : Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
lblStatus.Text = ""
Dim ping As Ping = New Ping()
Dim pingreply As PingReply = ping.Send(txtHost.Text)
txtPing.Text &= "Address: " & pingreply.Address.ToString() & Constants.vbCr
txtPing.Text &= "Roundtrip Time: " & pingreply.RoundtripTime & Constants.vbCr
txtPing.Text &= "TTL (Time To Live): " & pingreply.Options.Ttl & Constants.vbCr
txtPing.Text &= "Buffer Size: " & pingreply.Buffer.Length.ToString() & Constants.vbCr

Catch err As Exception
lblStatus.Text = err.Message
End Try
End Sub
End Class

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.



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!