-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkScanner.cs
More file actions
95 lines (87 loc) · 2.52 KB
/
NetworkScanner.cs
File metadata and controls
95 lines (87 loc) · 2.52 KB
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
using System;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace NetworkScanner
{
public partial class NetworkScanner : Form
{
NetPinger netPing = new NetPinger();
bool continueScan = true;
// Constructor to kick off network scanner
public NetworkScanner()
{
InitializeComponent();
netPing.RunPingSweepAsync();
netPing.PrintEvent += PrintResults;
}
private void PrintResults(object sender, string e)
{
IpAddress.Text = netPing.myIpAddress;
dataGridView1.Rows.Clear();
foreach (var record in netPing.networkIpRecords)
{
dataGridView1.Rows.Add(record.Name, record.IpAddress, record.Manufacturer, record.MacAddress, record.DateCreated);
}
}
private void StopButton_Click(object sender, EventArgs e)
{
if(StopButton.Text == "Stop")
{
continueScan = false;
StopButton.Text = "Start";
}
else
{
continueScan = true;
StopButton.Text = "Stop";
}
}
private void timer(object sender, EventArgs e)
{
if(continueScan)
{
ValidateSecurityDetails();
netPing.RunPingSweepAsync();
netPing.PrintEvent += PrintResults;
}
}
private void ValidateSecurityDetails()
{
if (EmailCheckbox.Checked && IsValidEmail(EmailTextBox.Text))
{
netPing.SendEmail = true;
netPing.EmailAddress = EmailTextBox.Text;
}
else
{
netPing.SendEmail = false;
}
if (SmsCheckBox.Checked && !string.IsNullOrEmpty(SmsTextBox.Text))
{
netPing.SendText = true;
netPing.PhoneNumber = SmsTextBox.Text;
}
else
{
netPing.SendText = false;
}
}
private bool IsValidEmail(string email)
{
if (email.Trim().EndsWith("."))
{
return false;
}
try
{
var addr = new MailAddress(email);
return addr.Address == email;
}
catch
{
return false;
}
}
}
}