Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

My.Computer.Network.Ping Method 

Pings the specified server.


' Usage
Dim value As Boolean = My.Computer.Network.Ping(hostNameOrAddress)
Dim value As Boolean = My.Computer.Network.Ping(address)
Dim value As Boolean = My.Computer.Network.Ping(hostNameOrAddress ,timeout)
Dim value As Boolean = My.Computer.Network.Ping(address ,timeout)
' Declaration
Public Function Ping( _
   ByVal hostNameOrAddress As String _
) As Boolean
' -or-
Public Function Ping( _
   ByVal address As System.Uri _
) As Boolean
' -or-
Public Function Ping( _
   ByVal hostNameOrAddress As String, _
   ByVal timeout As Integer _
) As Boolean
' -or-
Public Function Ping( _
   ByVal address As System.Uri, _
   ByVal timeout As Integer _
) As Boolean

Parameters

hostNameOrAddress

String. The URL, computer name, or IP number of the server to ping. Required.

address

Uri. The URI of the server to ping. Required.

timeout

Int32. Time threshold in milliseconds for contacting the destination. Default is 500. Required.

Boolean indicating whether or not the operation was successful.

The following conditions may cause an exception to be thrown:

The Ping method is not a fail-safe method for determining the availability of a remote computer: the ping port on the target computer may be turned off or the ping request may be blocked by a firewall or router.

The address passed to the Ping method must be DNS resolvable and cannot be preceded by "http://".

The following table lists examples of tasks involving the My.Computer.Network.Ping method.

To See

Determine whether a remote computer or host is available

How to: Determine if a Remote Computer is Available in Visual Basic

This example reports whether or not the server can be pinged by determining whether the Ping method returns True.

If My.Computer.Network.Ping("198.01.01.01") Then
   MsgBox("Server pinged successfully.")
Else
   MsgBox("Ping request timed out.")
End If

Replace "198.01.01.01" with the IP address, URL, or computer name of the server to ping.

This example reports whether or not the server can be pinged by determining whether the Ping method returned True and specifies a timeout interval of 1000 milliseconds.

If My.Computer.Network.Ping("www.cohowinery.com",1000) Then
   MsgBox("Server pinged successfully.")
Else
   MsgBox("Ping request timed out.")
End If

Replace "www.cohowinery.com" with the IP address, URL, or computer name of the server to ping.

Namespace: Microsoft.VisualBasic.Devices

Class: Network

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

The following permissions may be necessary:

Permission Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

SecurityPermission

Describes a set of security permissions applied to code. Associated enumeration: ControlPrincipal.

WebPermission

Controls rights to access HTTP Internet resources. Associated enumeration: Unrestricted.

SocketPermission

Controls rights to make or accept connections on a transport address. Associated enumeration: Unrestricted.

PerformanceCounterPermission

Controls access to a Windows NT performance counter component. Associated enumeration: Unrestricted.

NetworkInformationPermission

Controls access to network information and traffic statistics for the local computer. Associated enumeration: Ping.

For more information, see Code Access Security and Requesting Permissions.

Community Additions

ADD
Show:
© 2015 Microsoft