From c45b28ed107b945b23829438cc04e3ebe71668ab Mon Sep 17 00:00:00 2001 From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com> Date: Tue, 24 Mar 2020 15:55:49 +0100 Subject: [PATCH] Add "Ping" Method --- Misc/GenericExtensions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Misc/GenericExtensions.cs b/Misc/GenericExtensions.cs index 0554aee..7024a98 100644 --- a/Misc/GenericExtensions.cs +++ b/Misc/GenericExtensions.cs @@ -96,6 +96,23 @@ namespace CC_Functions.Misc WebResponse resp = req.GetResponse(); return resp.ResponseUri; } + + public static bool Ping(this Uri self) + { + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(self); + request.Timeout = 3000; + request.AllowAutoRedirect = true; + using WebResponse response = request.GetResponse(); + return true; + } + catch + { + return false; + } + } + public static Rectangle Round(this RectangleF self) => Rectangle.Round(self); public static Rectangle Ceiling(this RectangleF self) => Rectangle.Ceiling(self); }