From 0051e7bb50598667a90d1152334ec3b26d658a4e Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Thu, 24 Dec 2020 13:32:06 +0800 Subject: [PATCH] Feat ICMPing --- Netch/Utils/Utils.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Netch/Utils/Utils.cs b/Netch/Utils/Utils.cs index 8062057c..60dfff54 100644 --- a/Netch/Utils/Utils.cs +++ b/Netch/Utils/Utils.cs @@ -56,6 +56,18 @@ namespace Netch.Utils return timeout; } + public static int ICMPing(IPAddress ip, int timeout = 1000) + { + var reply = new Ping().Send(ip, timeout); + + if (reply?.Status == IPStatus.Success) + { + return Convert.ToInt32(reply.RoundtripTime); + } + + return timeout; + } + public static string GetCityCode(string Hostname) { if (Hostname.Contains(":"))