aboutsummaryrefslogtreecommitdiff
path: root/Pinger/MyNet/Form1.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Pinger/MyNet/Form1.cs')
-rw-r--r--Pinger/MyNet/Form1.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/Pinger/MyNet/Form1.cs b/Pinger/MyNet/Form1.cs
new file mode 100644
index 0000000..d09d9a1
--- /dev/null
+++ b/Pinger/MyNet/Form1.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Threading;
+using System.Net.NetworkInformation;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace MyNet {
+ public partial class myNetForm : Form {
+ public myNetForm() {
+ InitializeComponent();
+ Control.CheckForIllegalCrossThreadCalls = false;
+
+ Thread t = new Thread(PingStatus);
+ t.Start();
+ }
+
+ private void PingStatus() {
+ Ping p = new Ping();
+ PingReply pr;
+
+ while(true) {
+ try {
+ pr = p.Send(cbPingAddress.Text);
+ lblErrorMessage.Text = "";
+
+ if (pr.Status == IPStatus.Success) {
+ lblPing.Text = pr.RoundtripTime + "";
+
+ if (pr.RoundtripTime > 300) lblPing.BackColor = Color.Red;
+ else if (pr.RoundtripTime > 100) lblPing.BackColor = Color.Orange;
+ else if (pr.RoundtripTime > 10) lblPing.BackColor = Color.Yellow;
+ else lblPing.BackColor = Color.LightGreen;
+ }
+ else throw new Exception(pr.Status.ToString());
+ } catch (Exception ex) {
+ lblErrorMessage.Text = ex.Message;
+
+ lblPing.BackColor = Color.Red;
+ lblPing.Text = "-1";
+ }
+ Thread.Sleep(1000);
+ }
+ }
+
+ private void Form1_Load(object sender, EventArgs e) {
+ }
+ }
+}