Get Ping in Milliseconds
This function gives the programmer the ability to determine the time in milliseconds of a response from an IP address. This could be useful for determining lag or for a game's server browser, etc.
VB.NET
''' <summary>
''' Gets the time taken to ping an IP.
''' </summary>
''' <param name="hostNameOrAddress">IP or HostName to ping</param>
''' <returns>The time in milliseconds taken to ping the IP.</returns>
''' <remarks></remarks>
Public Shared Function GetPingMs(ByRef hostNameOrAddress As String)
Dim ping As New System.Net.NetworkInformation.Ping
Return ping.Send(hostNameOrAddress).RoundtripTime
End Function
' How to call this function (IP Address).
GetPingMs("127.0.0.1")
' How to call this function (HostName).
GetPingMs("www.dreamincode.net")
See Also
- </DIC> Submission - http://www.dreamincode.net/code/snippet1511.htm
page revision: 0, last edited: 16 Dec 2007 04:55