Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Pinging another computer

From Wiki

Jump to: navigation, search

For the 2.0 framework you will find this in the My namespace

  1. If My.Computer.Network.Ping("127.0.0.1") Then
  2.      'the computer was there
  3. Else
  4.      'the computer wasn't available
  5. End If


And here is a more elaborate example where you can get a lot more information then just ok or not ok like above.

  1. Imports System
  2. Imports System.Net
  3. Imports System.Net.NetworkInformation
  4.  
  5. Namespace PingProc
  6.  
  7.     Public Class Program
  8.  
  9.         Public Sub Main()
  10.  
  11.             Ping("127.0.0.1")
  12.             'Ping("cnn.com")
  13.         End Sub
  14.  
  15.  
  16.         Public Function Ping(ByVal hostname As String) As Integer
  17.  
  18.             Dim _ping As Ping = New Ping()
  19.  
  20.             Dim _reply As PingReply = _ping.Send(hostname)
  21.             If _reply.Status = IPStatus.Success Then
  22.  
  23.                 Console.WriteLine("Address: {0}", _reply.Address)
  24.                 Console.WriteLine("RoundTrip Time: {0}", _reply.RoundtripTime)
  25.                 Console.WriteLine("Time To Live: {0}", _reply.Options.Ttl)
  26.                 Console.WriteLine("Don't Fragment: {0}", _reply.Options.DontFragment)
  27.                 Console.WriteLine("Buffer Size: {0}", _reply.Buffer.Length)
  28.                 Console.WriteLine("Status: {0}", _reply.Status)
  29.  
  30.                 Console.ReadLine()
  31.                 Return (0)
  32.             Else
  33.                 Console.WriteLine("Error")
  34.                 Console.WriteLine("Status: {0}", _reply.Status)
  35.                 Console.ReadLine()
  36.                 Return (1)
  37.             End If
  38.         End Function
  39.     End Class
  40. end namespace

356 Rating: 1.8/5 (4 votes cast)