C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,008 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello!
How to check the response time of a remote machine?
Hi 12586429,
using System;
using System.Net.NetworkInformation;
public class Program
{
public static void Main(string[] args)
{
string remoteIpAddress = "192.168.0.1"; // Replace by your remote IP machine
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
byte[] buffer = new byte[32];
try
{
PingReply reply = pingSender.Send(remoteIpAddress, 1000, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine($"Response time: {reply.RoundtripTime} ms");
}
else
{
Console.WriteLine($"Ping failed with status: {reply.Status}");
}
}
catch (PingException ex)
{
Console.WriteLine($"Ping failed error: {ex.Message}");
}
}
}
Regards,