-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
810 lines (742 loc) · 27.9 KB
/
Copy pathMainForm.cs
File metadata and controls
810 lines (742 loc) · 27.9 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Network_Monitoring_Sytem
{
public partial class MainForm : Form
{
bool sidebarExpand;
bool devicesCollapsed;
// Create a router
Router router = new Router("Router1", new MACAddress(new byte[] { 0x00, 0x99, 0xBB, 0xCC, 0x55, 0xEE }));
// Create a switch
Switch sw = new Switch("Switch1", new MACAddress(new byte[] { 0x00, 0x99, 0xBB, 0xCC, 0xDD, 0xEE }));
// Create 3 PCs
static PC pc1 = new PC("PC1", new MACAddress(new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }));
static PC pc2 = new PC("PC2", new MACAddress(new byte[] { 0x00, 0x22, 0x33, 0x44, 0x55, 0x66 }));
static PC pc3 = new PC("PC3", new MACAddress(new byte[] { 0x00, 0x22, 0x33, 0x44, 0x55, 0x77 }));
// Create a Server
Server s1 = new Server("Server1");
// IPs of PCs and Router
public static string IP1;
public static string IP2;
public static string IP3;
public static string IProu;
// Interface of Each PC
static Interface pc1Iface = new Interface();
static Interface pc2Iface = new Interface();
static Interface pc3Iface = new Interface();
// Interface for Router
static Interface routerIface = new Interface();
// Interface of Switches
static Interface swIface1 = new Interface();
static Interface swIface2 = new Interface();
static Interface swIface3 = new Interface();
static Interface swIface4 = new Interface();
// Packet from PC1 to PC2
Packet packet1 = new Packet();
// Packet from PC1 to PC3
Packet packet2 = new Packet();
// Packet from PC2 to PC1
Packet packet3 = new Packet();
// Packet from PC2 to PC3
Packet packet4 = new Packet();
// Packet from PC3 to PC1
Packet packet5 = new Packet();
// Packet from PC3 to PC2
Packet packet6 = new Packet();
public MainForm()
{
InitializeComponent();
// Create interface for Router
routerIface.set_inter1("RouterInterface", IProu, new MACAddress(new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }));
// Create Interfaces for Switche
swIface1.set_inter1("SwitchInterface1", "212.154.25.36", new MACAddress(new byte[] { 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE }));
swIface2.set_inter1("SwitchInterface2", "155.255.688.25", new MACAddress(new byte[] { 0x00, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }));
swIface3.set_inter1("SwitchInterface3", "184.32.5.2", new MACAddress(new byte[] { 0x11, 0x22, 0xCC, 0xDD, 0xEE, 0xFF }));
swIface4.set_inter1("SwitchInterface4", "172.30.12.5", new MACAddress(new byte[] { 0x33, 0xAA, 0x55, 0xDD, 0xEE, 0xFF }));
// Create Interfaces for PCs
pc1Iface.set_inter(pc1, IP1);
pc2Iface.set_inter(pc2,IP2);
pc3Iface.set_inter(pc3,IP3);
// Connect the devices together by adding interfaces to their respective lists
router.AddInterface(routerIface);
sw.AddInterface(swIface1);
sw.AddInterface(swIface2);
sw.AddInterface(swIface3);
sw.AddInterface(swIface4);
pc1.AddInterface(pc1Iface);
pc2.AddInterface(pc2Iface);
// Add MAC address entries to the switch's forwarding table
sw.LearnAddress(pc1.MACAddress, swIface1);
sw.LearnAddress(pc2.MACAddress, swIface2);
sw.LearnAddress(pc3.MACAddress, swIface3);
// Access the variable from the source form
IP1 = PC1.ipadd;
IP2 = PC2.ipadd;
IP3 = PC3.ipadd;
IProu = Router_Config.ipadd;
// Use the value as needed
lblpc1.Text = IP1;
lblpc2.Text = IP2;
lblpc3.Text = IP3;
lbliprou.Text = IProu;
}
// Showing the Configuration Form for PC1
private void pcc1_Click(object sender, EventArgs e)
{
PC1 pc_1 = new PC1();
pc_1.Show();
this.Hide();
}
// Showing the Configuration Form for PC2
private void pcc2_Click(object sender, EventArgs e)
{
PC2 pc_2 = new PC2();
pc_2.Show();
this.Hide();
}
// Showing the Configuration Form for PC3
private void pcc3_Click(object sender, EventArgs e)
{
PC3 pc_3 = new PC3();
pc_3.Show();
this.Hide();
}
// Showing the Configuration Form for Router
private void rou_pic_Click(object sender, EventArgs e)
{
Router_Config rcc = new Router_Config();
rcc.Show();
this.Hide();
}
private void sidebarTimer_Tick(object sender, EventArgs e)
{
//SET maximum and minimum size of sidebar Panel
if (sidebarExpand)
{
//if sidebar is expand, minimize
sidebar.Width -= 10;
if (sidebar.Width == sidebar.MinimumSize.Width)
{
sidebarExpand = false;
sidebarTimer.Stop();
}
}
else
{
sidebar.Width += 10;
if (sidebar.Width == sidebar.MaximumSize.Width)
{
sidebarExpand = true;
sidebarTimer.Stop();
}
}
}
private void menubox_Click(object sender, EventArgs e)
{
//set timer interval to lowest to make it smoother
sidebarTimer.Start();
}
private void DevicesTimer_Tick(object sender, EventArgs e)
{
//SET maximum and minimum size of Devices Panel
if (devicesCollapsed)
{
devices_container.Height += 10;
if (devices_container.Height == devices_container.MaximumSize.Height)
{
devicesCollapsed = false;
DevicesTimer.Stop();
}
}
else
{
devices_container.Height -= 10;
if (devices_container.Height == devices_container.MinimumSize.Height)
{
devicesCollapsed = true;
DevicesTimer.Stop();
}
}
}
private void NetworkPic_Click(object sender, EventArgs e)
{
//set timer interval to lowest to make it smoother
DevicesTimer.Start();
}
// Showing the Exit
private void logoutbutton_Click(object sender, EventArgs e)
{
exit ex = new exit();
ex.Show();
this.Hide();
}
// Capturing the Packet
private void capturePacket_Click(object sender, EventArgs e)
{
if(pc1_2.Checked)
{
packet1.set_info(pc1Iface, pc2Iface, "Hello from PC1 to PC2");
// Capturing the packet
mainmessage.Text = s1.CapturePacket(packet1);
}
else if(pc1_3.Checked)
{
packet2.set_info(pc1Iface, pc3Iface, "Hello from PC1 to PC3");
// Capturing the packet
mainmessage.Text = s1.CapturePacket(packet2);
}
else if (pc2_1.Checked)
{
packet3.set_info(pc2Iface, pc1Iface, "Hello from PC2 to PC1");
// Capturing the packet
mainmessage.Text = s1.CapturePacket(packet3);
}
else if (pc2_3.Checked)
{
packet4.set_info(pc2Iface, pc3Iface, "Hello from PC2 to PC3");
// Capturing the packet
mainmessage.Text = s1.CapturePacket(packet4);
}
else if (pc3_1.Checked)
{
packet5.set_info(pc3Iface, pc1Iface, "Hello from PC3 to PC1");
// Capturing the packet
mainmessage.Text = s1.CapturePacket(packet5);
}
else if(pc3_2.Checked)
{
packet6.set_info(pc3Iface, pc2Iface, "Hello from PC3 to PC2");
// Capturing the packet
mainmessage.Text = s1.CapturePacket(packet6);
}
else
{
MessageBox.Show("Select an option to capture the packet", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void pc1_2_CheckedChanged(object sender, EventArgs e)
{
if(pc1_2.Checked == true)
{
// to allow selecting one at a time
pc1_3.Checked = false;
pc2_1.Checked = false;
pc2_3.Checked = false;
pc3_1.Checked = false;
pc3_2.Checked = false;
}
}
private void pc1_3_CheckedChanged(object sender, EventArgs e)
{
if (pc1_3.Checked == true)
{
// to allow selecting one at a time
pc1_2.Checked = false;
pc2_1.Checked = false;
pc2_3.Checked = false;
pc3_1.Checked = false;
pc3_2.Checked = false;
}
}
private void pc2_3_CheckedChanged(object sender, EventArgs e)
{
if (pc2_3.Checked == true)
{
// to allow selecting one at a time
pc1_3.Checked = false;
pc2_1.Checked = false;
pc1_2.Checked = false;
pc3_1.Checked = false;
pc3_2.Checked = false;
}
}
private void pc2_1_CheckedChanged(object sender, EventArgs e)
{
if (pc2_1.Checked == true)
{
// to allow selecting one at a time
pc1_3.Checked = false;
pc1_2.Checked = false;
pc2_3.Checked = false;
pc3_1.Checked = false;
pc3_2.Checked = false;
}
}
private void pc3_1_CheckedChanged(object sender, EventArgs e)
{
if (pc3_1.Checked == true)
{
// to allow selecting one at a time
pc1_3.Checked = false;
pc2_1.Checked = false;
pc2_3.Checked = false;
pc1_2.Checked = false;
pc3_2.Checked = false;
}
}
private void pc3_2_CheckedChanged(object sender, EventArgs e)
{
if (pc3_2.Checked == true)
{
// to allow selecting one at a time
pc1_3.Checked = false;
pc2_1.Checked = false;
pc2_3.Checked = false;
pc3_1.Checked = false;
pc1_2.Checked = false;
}
}
private void sendbutton_Click(object sender, EventArgs e)
{
if (pc12.Checked)
{
packet1.set_info(pc1Iface, pc2Iface, "Hello from PC1 to PC2");
// Sending the packet
sw.SendPacket(packet1, pc1Iface);
MessageBox.Show($"Packet SENT \r\n ", "Sent", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if (pc13.Checked)
{
packet2.set_info(pc1Iface, pc3Iface, "Hello from PC1 to PC3");
// Sending the packet
sw.SendPacket(packet2, pc1Iface);
MessageBox.Show("Packet SENT", "Sent", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if (pc21.Checked)
{
packet3.set_info(pc2Iface, pc1Iface, "Hello from PC2 to PC1");
// Sending the packet
sw.SendPacket(packet3, pc2Iface);
MessageBox.Show("Packet SENT", "Sent", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if (pc23.Checked)
{
packet4.set_info(pc2Iface, pc3Iface, "Hello from PC2 to PC3");
// Sending the packet
sw.SendPacket(packet4, pc2Iface);
MessageBox.Show("Packet SENT", "Sent", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if (pc31.Checked)
{
packet5.set_info(pc3Iface, pc1Iface, "Hello from PC3 to PC1");
// Sending the packet
sw.SendPacket(packet5, pc3Iface);
MessageBox.Show("Packet SENT", "Sent", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if (pc32.Checked)
{
packet6.set_info(pc3Iface, pc2Iface, "Hello from PC3 to PC2");
// Sending the packet
sw.SendPacket(packet6, pc3Iface);
MessageBox.Show("Packet SENT", "Sent", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Select an option to SEND Packet", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void pc12_CheckedChanged(object sender, EventArgs e)
{
if (pc12.Checked == true)
{
// to allow selecting one at a time
pc13.Checked = false;
pc21.Checked = false;
pc23.Checked = false;
pc31.Checked = false;
pc32.Checked = false;
}
}
private void pc13_CheckedChanged(object sender, EventArgs e)
{
if (pc13.Checked == true)
{
// to allow selecting one at a time
pc12.Checked = false;
pc21.Checked = false;
pc23.Checked = false;
pc31.Checked = false;
pc32.Checked = false;
}
}
private void pc23_CheckedChanged(object sender, EventArgs e)
{
if (pc23.Checked == true)
{
// to allow selecting one at a time
pc13.Checked = false;
pc21.Checked = false;
pc12.Checked = false;
pc31.Checked = false;
pc32.Checked = false;
}
}
private void pc21_CheckedChanged(object sender, EventArgs e)
{
if (pc21.Checked == true)
{
// to allow selecting one at a time
pc13.Checked = false;
pc12.Checked = false;
pc23.Checked = false;
pc31.Checked = false;
pc32.Checked = false;
}
}
private void pc31_CheckedChanged(object sender, EventArgs e)
{
if (pc31.Checked == true)
{
// to allow selecting one at a time
pc13.Checked = false;
pc21.Checked = false;
pc23.Checked = false;
pc12.Checked = false;
pc32.Checked = false;
}
}
private void pc32_CheckedChanged(object sender, EventArgs e)
{
if (pc32.Checked == true)
{
// to allow selecting one at a time
pc13.Checked = false;
pc21.Checked = false;
pc23.Checked = false;
pc31.Checked = false;
pc12.Checked = false;
}
}
private void receivebutton_Click(object sender, EventArgs e)
{
if (pc1_pc2.Checked)
{
// Receiving the packet
if (pc2Iface.receivepacket(packet1) == true)
{
MessageBox.Show("Packet RECEIVED from PC1 to PC2", "Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Packet NOT Received", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (pc1_pc3.Checked)
{
// Receiving the packet
if (pc3Iface.receivepacket(packet2) == true)
{
MessageBox.Show("Packet RECEIVED from PC1 to PC3", "Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Packet NOT Received", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (pc2_pc1.Checked)
{
// Receiving the packet
if (pc1Iface.receivepacket(packet3) == true)
{
MessageBox.Show("Packet RECEIVED from PC2 to PC1", "Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Packet NOT Received", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (pc2_pc3.Checked)
{
// Receiving the packet
if (pc3Iface.receivepacket(packet4) == true)
{
MessageBox.Show("Packet RECEIVED from PC2 to PC3", "Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Packet NOT Received", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (pc3_pc1.Checked)
{
// Receiving the packet
if (pc1Iface.receivepacket(packet5) == true)
{
MessageBox.Show("Packet RECEIVED from PC3 to PC1", "Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Packet NOT Received", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (pc3_pc2.Checked)
{
// Receiving the packet
if (pc2Iface.receivepacket(packet6) == true)
{
MessageBox.Show("Packet RECEIVED from PC3 to PC2", "Received", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Packet NOT Received", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Select an option to RECEIVE packet", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void pc1_pc2_CheckedChanged(object sender, EventArgs e)
{
if (pc1_pc2.Checked == true)
{
// to allow selecting one at a time
pc1_pc3.Checked = false;
pc2_pc1.Checked = false;
pc2_pc3.Checked = false;
pc3_pc1.Checked = false;
pc3_pc2.Checked = false;
}
}
private void pc1_pc3_CheckedChanged(object sender, EventArgs e)
{
if (pc1_pc3.Checked == true)
{
// to allow selecting one at a time
pc3_pc2.Checked = false;
pc2_pc1.Checked = false;
pc2_pc3.Checked = false;
pc3_pc1.Checked = false;
pc1_pc2.Checked = false;
}
}
private void pc2_pc3_CheckedChanged(object sender, EventArgs e)
{
if (pc2_pc3.Checked == true)
{
// to allow selecting one at a time
pc1_pc3.Checked = false;
pc2_pc1.Checked = false;
pc3_pc2.Checked = false;
pc3_pc1.Checked = false;
pc1_pc2.Checked = false;
}
}
private void pc2_pc1_CheckedChanged(object sender, EventArgs e)
{
if (pc2_pc1.Checked == true)
{
// to allow selecting one at a time
pc1_pc3.Checked = false;
pc3_pc2.Checked = false;
pc2_pc3.Checked = false;
pc3_pc1.Checked = false;
pc1_pc2.Checked = false;
}
}
private void pc3_pc1_CheckedChanged(object sender, EventArgs e)
{
if (pc3_pc1.Checked == true)
{
// to allow selecting one at a time
pc1_pc3.Checked = false;
pc2_pc1.Checked = false;
pc2_pc3.Checked = false;
pc3_pc2.Checked = false;
pc1_pc2.Checked = false;
}
}
private void pc3_pc2_CheckedChanged(object sender, EventArgs e)
{
if (pc3_pc2.Checked == true)
{
// to allow selecting one at a time
pc1_pc3.Checked = false;
pc2_pc1.Checked = false;
pc2_pc3.Checked = false;
pc3_pc1.Checked = false;
pc1_pc2.Checked = false;
}
}
// Triggering the Poll functions
private void pollbutton_Click(object sender, EventArgs e)
{
if (pc1poll.Checked == true)
{
pollmessage.Text = s1.poll(pc1Iface, pc1);
}
else if (pc2poll.Checked == true)
{
pollmessage.Text = s1.poll(pc2Iface, pc2);
}
else if (pc3poll.Checked == true)
{
pollmessage.Text = s1.poll(pc3Iface, pc3);
}
else if (switchpoll.Checked == true)
{
pollmessage.Text = s1.poll(swIface4, sw);
}
else if (routerpoll.Checked == true)
{
pollmessage.Text = s1.poll(routerIface, router);
}
else
{
MessageBox.Show("Select Device to POLL", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void pc1poll_CheckedChanged(object sender, EventArgs e)
{
if (pc1poll.Checked == true)
{
// to allow selecting one at a time
pc2poll.Checked = false;
pc3poll.Checked = false;
switchpoll.Checked = false;
routerpoll.Checked = false;
}
}
private void pc2poll_CheckedChanged(object sender, EventArgs e)
{
if (pc2poll.Checked == true)
{
// to allow selecting one at a time
pc1poll.Checked = false;
pc3poll.Checked = false;
switchpoll.Checked = false;
routerpoll.Checked = false;
}
}
private void pc3poll_CheckedChanged(object sender, EventArgs e)
{
if (pc3poll.Checked == true)
{
// to allow selecting one at a time
pc2poll.Checked = false;
pc1poll.Checked = false;
switchpoll.Checked = false;
routerpoll.Checked = false;
}
}
private void switchpoll_CheckedChanged(object sender, EventArgs e)
{
if (switchpoll.Checked == true)
{
// to allow selecting one at a time
pc2poll.Checked = false;
pc3poll.Checked = false;
pc1poll.Checked = false;
routerpoll.Checked = false;
}
}
private void routerpoll_CheckedChanged(object sender, EventArgs e)
{
if (routerpoll.Checked == true)
{
// to allow selecting one at a time
pc2poll.Checked = false;
pc3poll.Checked = false;
switchpoll.Checked = false;
pc1poll.Checked = false;
}
}
// Showing the Ping form to trigger the ping funtion of server
private void pingbutton_Click(object sender, EventArgs e)
{
if (pc1ping.Checked == true)
{
ping p1 = new ping(PC1.ipadd);
p1.Show();
}
else if (pc2ping.Checked == true)
{
ping p1 = new ping(PC2.ipadd);
p1.Show();
}
else if (pc3ping.Checked == true)
{
ping p1 = new ping(PC3.ipadd);
p1.Show();
}
else if (switchping.Checked == true)
{
ping p1 = new ping(swIface4.IPAddress);
p1.Show();
}
else if(routerping.Checked == true)
{
ping p1 = new ping(Router_Config.ipadd);
p1.Show();
}
else
{
MessageBox.Show("Select Option to PING", "ERROR!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void pc1ping_CheckedChanged(object sender, EventArgs e)
{
if (pc1ping.Checked == true)
{
// to allow selecting one at a time
pc2ping.Checked = false;
pc3ping.Checked = false;
switchping.Checked = false;
routerping.Checked = false;
}
}
private void pc2ping_CheckedChanged(object sender, EventArgs e)
{
if (pc2ping.Checked == true)
{
// to allow selecting one at a time
pc1ping.Checked = false;
pc3ping.Checked = false;
switchping.Checked = false;
routerping.Checked = false;
}
}
private void pc3ping_CheckedChanged(object sender, EventArgs e)
{
if (pc3ping.Checked == true)
{
// to allow selecting one at a time
pc2ping.Checked = false;
pc1ping.Checked = false;
switchping.Checked = false;
routerping.Checked = false;
}
}
private void switchping_CheckedChanged(object sender, EventArgs e)
{
if (switchping.Checked == true)
{
// to allow selecting one at a time
pc2ping.Checked = false;
pc3ping.Checked = false;
pc1ping.Checked = false;
routerping.Checked = false;
}
}
private void routerping_CheckedChanged(object sender, EventArgs e)
{
if (routerping.Checked == true)
{
// to allow selecting one at a time
pc2ping.Checked = false;
pc3ping.Checked = false;
switchping.Checked = false;
pc1ping.Checked = false;
}
}
}
}