-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmPDV.cs
97 lines (86 loc) · 3.35 KB
/
frmPDV.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.NetworkInformation;
namespace T.I_Local
{
public partial class frmPDV : Form
{
protected StringBuilder strPingInfo = new StringBuilder(400);
Timer refreshTimer = new Timer();
public frmPDV()
{
InitializeComponent();
}
private void frmPDV_Load(object sender, EventArgs e)
{
refreshTimer.Interval = 10000; //10 seconds in milliseconds
refreshTimer.Tick += new EventHandler(RefreshTimer_Tick);
refreshTimer.Start();
}
private void refreshForm()
{
strPingInfo.Clear();
string[] HostNames = File.ReadAllLines(@"C:\Users\USUARIO\Downloads\Imagens\pdv.txt", Encoding.UTF8);
foreach (string HostName in HostNames)
{
if (HostName != "")
{
strPingInfo.Append(PingReply(HostName));
strPingInfo.Append("---------------------------------------------------\r\n\r\n");
}
}
tbPingReply.Text = strPingInfo.ToString();
}
public string PingReply(string inHostName)
{
StringBuilder strReply = new StringBuilder(200);
Ping p1 = new Ping();
try
{
PingReply reply = p1.Send(inHostName);
if (reply.Status == IPStatus.Success)
{
strReply.AppendFormat("Hostname: {0} \r", inHostName);
strReply.AppendFormat("Endereço IP: {0} \r", reply.Address.ToString());
strReply.AppendFormat("Time: {0} ms \r", reply.RoundtripTime);
strReply.AppendFormat("TTL: {0} \r", reply.Options == null ? "" : reply.Options.Ttl.ToString());
strReply.AppendFormat("Don't fragment: {0} \r", reply.Options == null ? "" : reply.Options.DontFragment.ToString());
strReply.AppendFormat("Bytes: {0} \r\n", reply.Buffer.Length);
lblServ1.Text = "ON";
lblServ1.BackColor = Color.ForestGreen;
}
else if (reply.Status == IPStatus.TimedOut)
{
strReply.AppendFormat("Hostname: {0} \r", inHostName);
strReply.Append("Notice: Request timed out \r");
lblServ1.Text = "OFF";
lblServ1.BackColor = Color.Red;
}
}
catch (Exception ex)
{
strReply.Clear();
strReply.AppendFormat("Hostname: {0} \r", inHostName);
strReply.AppendFormat("Erro: {0} \r", ex.Message);
lblServ1.Text = "OFF";
lblServ1.BackColor = Color.Red;
}
return strReply.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
refreshForm();
}
private void RefreshTimer_Tick(object sender, EventArgs e)
{
refreshForm();
}
}
}