-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPing.cs
36 lines (30 loc) · 1.01 KB
/
Ping.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
internal class Ping
{
public string pingHostPrint(ref string url) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
System.Diagnostics.Stopwatch timer = new Stopwatch();
timer.Start();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
Console.Write(" Ping: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(timer.ElapsedMilliseconds + "ms");
Console.ResetColor();
if (timer.ElapsedMilliseconds == 1000) {
Console.WriteLine(" Ping: R.I.P");
}
return string.Empty;
}
}
}