CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: VB.NET

.NET Ping a Host

232 Views
Copy Code Show/Hide Line Numbers
   1:   
   2:  Imports System.Net
   3:  Imports System.Net.NetworkInformation
   4:  Imports System.Threading
   5:  Imports System.Text
   6:   
   7:  Public Class Form1
   8:   
   9:      Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
  10:          MemoEdit1.Text = ""
  11:          Dim OhNo As String = "Oh No, {0} is not available" + vbCrLf
  12:          Dim Yeeha As String = "{0} is available" + vbCrLf
  13:          Dim who As String = "http://HWSFAX/AFWeb/Services.asmx"
  14:          MemoEdit1.Text += String.Format(If(IsActive(who), Yeeha, OhNo), who)
  15:          who = String.Format("http://www.{0}.com", "".PadLeft(30, "z"c))
  16:          MemoEdit1.Text += String.Format(If(IsActive(who), Yeeha, OhNo), who)
  17:          who = "www.comcast.net"
  18:          MemoEdit1.Text += String.Format(If(IsActive(who), Yeeha, OhNo), who)
  19:      End Sub
  20:   
  21:      Private Function IsActive(ByVal who As String) As Boolean
  22:          IsActive = False
  23:          Try
  24:              Dim ub As New System.UriBuilder(who)
  25:              Dim url As New System.Uri(ub.Uri.ToString)
  26:              IsActive = My.Computer.Network.Ping(url.DnsSafeHost, 12000)
  27:          Catch ex As Exception
  28:   
  29:          End Try
  30:      End Function
  31:   
  32:  End Class
by Thom Lamb
  June 25, 2010 @ 10:13am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate