chiwormjava 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/java.json +29 -52
  2. package/package.json +1 -1
  3. package/readme.md +645 -993
package/readme.md CHANGED
@@ -42,107 +42,175 @@ javacodewatch
42
42
 
43
43
  ---
44
44
 
45
- ## 🧠 What it does
46
-
47
- * Opens a local server
48
- * Launches your browser
49
- * Shows Java code snippets
50
- * Click → View code
51
- * Click → Copy code
52
-
53
45
  ---
46
+ Step 1: Place devices
47
+ Add in Packet Tracer:
48
+ 2 Routers (2621XM)
49
+ 2 Switches (2960)
50
+ 4 PCs
51
+
52
+ Arrange as:
53
+ PC1 PC2 PC3 PC4
54
+ | | | |
55
+ Switch1 Switch2
56
+ | |
57
+ Router1 ---- WAN ---- Router2
58
+
59
+ Step 2: Add Serial Ports
60
+ Click Router -> Physical tab
61
+ Turn Power OFF
62
+ Insert WIC-2T module
63
+ Turn Power ON
64
+ Now Serial0/0/0 and Serial0/0/1 will be available
65
+
66
+ Step 3: Connect cables
67
+ LAN:
68
+ PC to Switch using Copper Straight-Through
69
+ Switch to Router using Copper Straight-Through
70
+
71
+ WAN:
72
+ Use Serial DCE cable
73
+ Router1 Serial0/0/0 to Router2 Serial0/0/0
74
+
75
+ Step 4: Configure Router1
76
+ enable
77
+ configure terminal
78
+
79
+ interface gigabitEthernet 0/0
80
+ ip address 192.168.1.1 255.255.255.0
81
+ no shutdown
82
+ exit
83
+
84
+ interface serial 0/0/0
85
+ ip address 172.16.1.1 255.255.255.252
86
+ clock rate 64000
87
+ no shutdown
88
+ exit
89
+
90
+ Step 5: Configure Router2
91
+ enable
92
+ configure terminal
93
+
94
+ interface gigabitEthernet 0/0
95
+ ip address 10.0.0.1 255.255.255.248
96
+ no shutdown
97
+ exit
98
+
99
+ interface serial 0/0/0
100
+ ip address 172.16.1.2 255.255.255.252
101
+ no shutdown
102
+ exit
103
+
104
+ Step 6: Configure PCs
105
+ Left network:
106
+ PC1 IP 192.168.1.2 Mask 255.255.255.0 Gateway 192.168.1.1
107
+ PC2 IP 192.168.1.3 Gateway 192.168.1.1
108
+
109
+ Right network:
110
+ PC3 IP 10.0.0.2 Mask 255.255.255.248 Gateway 10.0.0.1
111
+ PC4 IP 10.0.0.3 Gateway 10.0.0.1
112
+
113
+ Step 7: Configure Routing
114
+ Router1:
115
+ ip route 10.0.0.0 255.255.255.248 172.16.1.2
116
+
117
+ Router2:
118
+ ip route 192.168.1.0 255.255.255.0 172.16.1.1
119
+
120
+ Step 8: Verify interfaces
121
+ Run:
122
+ show ip interface brief
54
123
 
55
- ## 📸 Features
124
+ Status should be up up
125
+ If not, use no shutdown
56
126
 
57
- * 📚 Java DSA snippets (LinkedList, etc.)
58
- * 🖱️ One-click code view
59
- * 📋 Copy to clipboard
60
- * 🌙 Clean dark UI
127
+ Step 9: Test connectivity
128
+ From PC1:
129
+ ping 10.0.0.2
61
130
 
62
- ---
131
+ Expected reply from destination
63
132
 
64
- ## ▶️ Usage
133
+ Step 10: Simulation Mode
134
+ Click Simulation
135
+ Reset Simulation
136
+ Edit Filters and select ARP and ICMP
65
137
 
66
- After running the command:
138
+ Send packet using Add Simple PDU from PC1 to PC3
139
+ Click Play or Capture/Forward
67
140
 
68
- ```bash
69
- javacodewatch
70
- ```
141
+ Expected packet flow:
142
+ PC1 -> Switch1 -> Router1 -> Router2 -> Switch2 -> PC3
71
143
 
72
- 👉 Your browser will open automatically:
144
+ First ARP then ICMP communication successful
73
145
 
74
- ```
75
- http://localhost:3000
76
- ```
77
146
 
78
- ---
79
147
 
80
- Armstrong
148
+ Step 1: Setting Up the Topology
149
+ Add devices:
150
+ 1 Router (2911 or similar)
151
+ 1 Switch (2960)
152
+ 3 PCs (PC0, PC1, PC2)
153
+ 1 Cloud or Server
81
154
 
82
- <?php
83
- $num = 153;
155
+ Step 2: Assign IP Addresses
156
+ Private Network:
157
+ PC0 IP 192.168.1.2 Mask 255.255.255.0 Gateway 192.168.1.1
158
+ PC1 IP 192.168.1.3 Mask 255.255.255.0 Gateway 192.168.1.1
159
+ PC2 IP 192.168.1.4 Mask 255.255.255.0 Gateway 192.168.1.1
84
160
 
85
- $temp = $num;
86
- $sum = 0;
161
+ Step 3: Configure Router Interfaces
162
+ Router> enable
163
+ Router# configure terminal
87
164
 
88
- // Count number of digits
89
- $digits = strlen($num);
165
+ Interface gig0/0
166
+ Router(config)# interface gig0/0
167
+ Router(config-if)# ip address 192.168.1.1 255.255.255.0
168
+ Router(config-if)# no shutdown
90
169
 
91
- while ($temp > 0) {
92
- $rem = $temp % 10;
93
- $sum += pow($rem, $digits);
94
- $temp = (int)($temp / 10);
95
- }
170
+ Interface gig0/1
171
+ Router(config)# interface gig0/1
172
+ Router(config-if)# ip address 203.0.113.1 255.255.255.0
173
+ Router(config-if)# no shutdown
96
174
 
175
+ Assign IP to Cloud/Server
176
+ IP 203.0.113.2
177
+ Mask 255.255.255.0
97
178
 
98
- if ($sum == $num) {
99
- echo "$num is an Armstrong number";
100
- } else {
101
- echo "$num is not an Armstrong number";
102
- }
103
- ?>
179
+ Step 4: Configure NAT
180
+ Define inside and outside interfaces
181
+ Router(config)# interface gig0/0
182
+ Router(config-if)# ip nat inside
183
+ Router(config-if)# exit
104
184
 
105
- ---
185
+ Router(config)# interface gig0/1
186
+ Router(config-if)# ip nat outside
187
+ Router(config-if)# exit
106
188
 
107
- <?php
108
- $img = imagecreatetruecolor(500, 350);
189
+ Configure PAT
190
+ Router(config)# access-list 1 permit 192.168.1.0 0.0.0.255
191
+ Router(config)# ip nat inside source list 1 interface gig0/1 overload
109
192
 
110
- $white = imagecolorallocate($img, 255, 255, 255);
111
- $black = imagecolorallocate($img, 0, 0, 0);
112
- $red = imagecolorallocate($img, 255, 0, 0);
113
- $blue = imagecolorallocate($img, 0, 0, 255);
114
- $green = imagecolorallocate($img, 0, 255, 0);
115
- $yellow= imagecolorallocate($img, 255, 255, 0);
193
+ Step 5: Configure Routing
194
+ Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2
116
195
 
117
- imagefill($img, 0, 0, $white);
196
+ Step 6: Test Configuration
197
+ From PC command prompt:
198
+ ping 203.0.113.2
118
199
 
119
- imagerectangle($img, 20, 20, 120, 100, $black);
200
+ If reply is received, NAT is working
120
201
 
121
- imagefilledrectangle($img, 140, 20, 240, 100, $green);
202
+ Verify NAT translations
203
+ Router# show ip nat translations
122
204
 
123
- imageellipse($img, 350, 70, 80, 80, $red);
124
205
 
125
- imagefilledellipse($img, 450, 70, 80, 80, $yellow);
126
206
 
127
- imageline($img, 20, 150, 200, 250, $blue);
128
207
 
129
- $points = array(300,150, 350,250, 250,250);
130
- imagepolygon($img, $points, 3, $black);
131
208
 
132
- $points2 = array(400,150, 450,250, 350,250);
133
- imagefilledpolygon($img, $points2, 3, $red);
134
209
 
135
- imagearc($img, 100, 300, 100, 50, 0, 180, $blue);
136
210
 
137
- imagestring($img, 5, 180, 300, "Shapes Demo", $black);
138
211
 
139
- header("Content-Type: image/png");
140
- imagepng($img);
141
212
 
142
- imagedestroy($img);
143
- ?>
144
213
 
145
- ---
146
214
 
147
215
 
148
216
 
@@ -154,19 +222,67 @@ imagedestroy($img);
154
222
 
155
223
 
156
224
 
225
+ AIM:
226
+ To analyze packet fragmentation by changing packet size and observing its effect using Wireshark.
157
227
 
228
+ Step 1: Open Wireshark
229
+ Launch Wireshark
230
+ Select active interface (WiFi or Ethernet)
231
+ Click Start Capture
158
232
 
233
+ Step 2: Check MTU size
234
+ Open Command Prompt and run:
235
+ netsh interface ipv4 show subinterfaces
236
+ Note MTU value (usually 1500 bytes)
159
237
 
238
+ Step 3: Test without fragmentation
239
+ ping 8.8.8.8 -f -l 1472
240
+ 1472 + 28 header = 1500, fits MTU
241
+ Output: Reply received, no fragmentation
160
242
 
243
+ Step 4: Force fragmentation error
244
+ ping 8.8.8.8 -f -l 2000
245
+ Output: Packet needs to be fragmented but DF set
246
+ Meaning: Packet too large and fragmentation not allowed
161
247
 
248
+ Step 5: Allow fragmentation
249
+ ping 8.8.8.8 -l 2000
250
+ Packet is divided into fragments
251
+ May observe delay or packet loss
162
252
 
253
+ Step 6: Analyze in Wireshark
254
+ Apply filter:
255
+ ip.flags.mf == 1 or ip.frag_offset > 0
163
256
 
257
+ Observation:
258
+ Multiple packets for single ping
259
+ Fragmented packets visible
164
260
 
261
+ Observations:
262
+ Fragmented packets have same Identification ID
263
+ Different Fragment Offset values
264
+ MF flag indicates more fragments
265
+ Last packet has MF = 0
165
266
 
267
+ Performance Impact:
268
+ More packets generated
269
+ Increased delay
270
+ Possible packet loss
166
271
 
272
+ Final Observation:
273
+ Small packet: No fragmentation
274
+ Large packet with DF: Error
275
+ Large packet without DF: Fragmentation occurs
167
276
 
277
+ Conclusion:
278
+ If packet size exceeds MTU, it is divided into smaller fragments, affecting performance
168
279
 
280
+ Output:
281
+ Ping command results showing success or error
282
+ Wireshark showing fragmented packets using filter
169
283
 
284
+ Result:
285
+ Fragmentation observed and analyzed successfully
170
286
 
171
287
 
172
288
 
@@ -183,112 +299,93 @@ imagedestroy($img);
183
299
 
184
300
 
185
301
 
186
- <?php
187
- // CONNECT
188
- $conn = mysqli_connect("localhost","root","");
189
302
 
190
- if(!$conn){
191
- die("Connection Failed");
192
- }
193
303
 
194
- // CREATE DB
195
- mysqli_query($conn, "CREATE DATABASE IF NOT EXISTS testdb");
196
304
 
197
- // SELECT DB
198
- mysqli_select_db($conn, "testdb");
305
+ AIM:
306
+ To identify vulnerabilities and secure the network using Access Control List (ACL) and Port Security.
199
307
 
200
- // CREATE TABLE
201
- mysqli_query($conn, "CREATE TABLE IF NOT EXISTS student(
202
- id INT AUTO_INCREMENT PRIMARY KEY,
203
- name VARCHAR(50),
204
- email VARCHAR(50)
205
- )");
308
+ Step 1: Topology Setup
309
+ Add devices:
310
+ 1 Router (2911)
311
+ 1 Switch (2960)
312
+ 2 PCs
206
313
 
207
- // INSERT
208
- if(isset($_POST['add'])){
209
- $name = $_POST['name'];
210
- $email = $_POST['email'];
314
+ Step 2: Connections
315
+ PC1 FastEthernet0 to Switch Fa0/1 using Copper Straight-Through
316
+ PC2 FastEthernet0 to Switch Fa0/2 using Copper Straight-Through
317
+ Switch Fa0/24 to Router GigabitEthernet0/0
211
318
 
212
- mysqli_query($conn,"INSERT INTO student(name,email) VALUES('$name','$email')");
213
- }
319
+ Step 3: Configure PCs
320
+ PC1 IP 192.168.1.10 Mask 255.255.255.0 Gateway 192.168.1.1
321
+ PC2 IP 192.168.1.20 Mask 255.255.255.0 Gateway 192.168.1.1
214
322
 
215
- // DELETE
216
- if(isset($_GET['delete'])){
217
- $id = $_GET['delete'];
218
- mysqli_query($conn,"DELETE FROM student WHERE id=$id");
219
- }
323
+ Step 4: Configure Router
324
+ enable
325
+ configure terminal
326
+ interface g0/0
327
+ ip address 192.168.1.1 255.255.255.0
328
+ no shutdown
329
+ exit
220
330
 
221
- // UPDATE
222
- if(isset($_POST['update'])){
223
- $id = $_POST['id'];
224
- $name = $_POST['name'];
225
- $email = $_POST['email'];
331
+ Step 5: Test Before Security
332
+ From PC2:
333
+ ping 192.168.1.10
334
+ Communication should be successful
226
335
 
227
- mysqli_query($conn,"UPDATE student SET name='$name', email='$email' WHERE id=$id");
228
- }
336
+ Step 6: Apply ACL
337
+ access-list 1 deny 192.168.1.20
338
+ access-list 1 permit any
229
339
 
230
- // FETCH FOR EDIT
231
- $editData = null;
232
- if(isset($_GET['edit'])){
233
- $id = $_GET['edit'];
234
- $res = mysqli_query($conn,"SELECT * FROM student WHERE id=$id");
235
- $editData = mysqli_fetch_assoc($res);
236
- }
237
- ?>
340
+ Apply ACL:
341
+ interface g0/0
342
+ ip access-group 1 in
343
+ exit
238
344
 
239
- <!DOCTYPE html>
240
- <html>
241
- <body>
345
+ Step 7: Test After Security
346
+ From PC2:
347
+ ping 192.168.1.10
348
+ Should fail
242
349
 
243
- <h2>Student Form</h2>
350
+ From PC1:
351
+ ping 192.168.1.20
352
+ Should work
244
353
 
245
- <form method="post">
246
- <input type="hidden" name="id" value="<?php echo $editData['id'] ?? ''; ?>">
354
+ Step 8: Configure Port Security on Switch
355
+ enable
356
+ configure terminal
357
+ interface fa0/1
358
+ switchport mode access
359
+ switchport port-security
360
+ switchport port-security maximum 1
361
+ exit
247
362
 
248
- Name: <input type="text" name="name" value="<?php echo $editData['name'] ?? ''; ?>"><br><br>
249
- Email: <input type="text" name="email" value="<?php echo $editData['email'] ?? ''; ?>"><br><br>
363
+ Vulnerabilities Identified:
364
+ No access control
365
+ No device restriction
366
+ No traffic filtering
250
367
 
251
- <?php if($editData){ ?>
252
- <input type="submit" name="update" value="Update">
253
- <?php } else { ?>
254
- <input type="submit" name="add" value="Add">
255
- <?php } ?>
256
- </form>
368
+ Security Measures Applied:
369
+ ACL controls communication between devices
370
+ Port Security restricts number of devices per port
257
371
 
258
- <hr>
372
+ Additional Concepts:
373
+ IDS detects suspicious activities such as unusual traffic
374
+ IPsec encrypts data for secure transmission
259
375
 
260
- <h2>Student Data</h2>
376
+ Simulation (Optional):
377
+ Use Simulation mode
378
+ Filter ICMP
379
+ Observe packet drop due to ACL
261
380
 
262
- <table border="1">
263
- <tr>
264
- <th>ID</th>
265
- <th>Name</th>
266
- <th>Email</th>
267
- <th>Action</th>
268
- </tr>
381
+ Final Result:
382
+ PC2 is blocked
383
+ PC1 is allowed
384
+ Switch ports are secured
385
+ Network is protected successfully
269
386
 
270
- <?php
271
- $result = mysqli_query($conn,"SELECT * FROM student");
272
387
 
273
- while($row = mysqli_fetch_assoc($result)){
274
- ?>
275
- <tr>
276
- <td><?php echo $row['id']; ?></td>
277
- <td><?php echo $row['name']; ?></td>
278
- <td><?php echo $row['email']; ?></td>
279
- <td>
280
- <a href="?edit=<?php echo $row['id']; ?>">Edit</a>
281
- <a href="?delete=<?php echo $row['id']; ?>">Delete</a>
282
- </td>
283
- </tr>
284
- <?php } ?>
285
-
286
- </table>
287
-
288
- </body>
289
- </html>
290
388
 
291
- ---
292
389
 
293
390
 
294
391
 
@@ -310,52 +407,107 @@ while($row = mysqli_fetch_assoc($result)){
310
407
 
311
408
 
312
409
 
410
+ AIM:
411
+ To demonstrate IP Spoofing attack and implement security measures to prevent unauthorized access.
313
412
 
413
+ Step 1: Topology Setup
414
+ Devices required:
415
+ 1 Router (2911)
416
+ 1 Switch (2960)
417
+ PC1 (Trusted user)
418
+ PC2 (Attacker)
419
+ 1 Server
314
420
 
421
+ Connections:
422
+ PC1 to Switch Fa0/1
423
+ PC2 to Switch Fa0/2
424
+ Switch Fa0/24 to Router G0/0
425
+ Server to Router G0/1
315
426
 
427
+ Step 2: IP Configuration
428
+ PC1 IP 192.168.1.10 Gateway 192.168.1.1
429
+ PC2 IP 192.168.1.20 Gateway 192.168.1.1
430
+ Server IP 10.0.0.2 Gateway 10.0.0.1
316
431
 
432
+ Step 3: Configure Router
433
+ enable
434
+ configure terminal
317
435
 
436
+ interface g0/0
437
+ ip address 192.168.1.1 255.255.255.0
438
+ no shutdown
439
+ exit
318
440
 
441
+ interface g0/1
442
+ ip address 10.0.0.1 255.255.255.0
443
+ no shutdown
444
+ exit
319
445
 
446
+ Step 4: Configure Routing
447
+ ip route 10.0.0.0 255.255.255.0 10.0.0.1
320
448
 
449
+ Step 5: Apply Trust-Based ACL
450
+ access-list 10 permit 192.168.1.10
451
+ access-list 10 deny any
321
452
 
453
+ interface g0/0
454
+ ip access-group 10 in
322
455
 
456
+ Step 6: Test Before Attack
457
+ From PC1:
458
+ ping 10.0.0.2 (should work)
323
459
 
324
- $img = imagecreatetruecolor(500, 350);
460
+ From PC2:
461
+ ping 10.0.0.2 (should fail)
325
462
 
326
- $white = imagecolorallocate($img, 255, 255, 255);
327
- $black = imagecolorallocate($img, 0, 0, 0);
328
- $red = imagecolorallocate($img, 255, 0, 0);
329
- $blue = imagecolorallocate($img, 0, 0, 255);
330
- $green = imagecolorallocate($img, 0, 255, 0);
331
- $yellow= imagecolorallocate($img, 255, 255, 0);
463
+ Step 7: Simulate IP Spoofing
464
+ Change PC2 IP to 192.168.1.10
332
465
 
333
- imagefill($img, 0, 0, $white);
466
+ Test again:
467
+ ping 10.0.0.2 (should work)
334
468
 
335
- imagerectangle($img, 20, 20, 120, 100, $black);
336
- imagefilledrectangle($img, 140, 20, 240, 100, $green);
469
+ Step 8: Impact
470
+ Unauthorized access
471
+ Security bypass
472
+ Fake identity
337
473
 
338
- imageellipse($img, 350, 70, 80, 80, $red);
339
- imagefilledellipse($img, 450, 70, 80, 80, $yellow);
474
+ Step 9: Countermeasure 1 Anti-Spoofing ACL
475
+ ip access-list extended ANTI-SPOOF
476
+ deny ip 192.168.1.0 0.0.0.255 any
477
+ permit ip any any
340
478
 
341
- imageline($img, 20, 150, 200, 250, $blue);
479
+ interface g0/1
480
+ ip access-group ANTI-SPOOF in
342
481
 
343
- $points = [300,150, 350,250, 250,250];
344
- imagepolygon($img, $points, 3, $black);
482
+ Step 10: Countermeasure 2 uRPF
483
+ interface g0/0
484
+ ip verify unicast source reachable-via rx
345
485
 
346
- $points2 = [400,150, 450,250, 350,250];
347
- imagefilledpolygon($img, $points2, 3, $red);
486
+ Step 11: Switch Port Security
487
+ enable
488
+ configure terminal
348
489
 
349
- imagearc($img, 100, 300, 100, 50, 0, 180, $blue);
490
+ interface fa0/1
491
+ switchport mode access
492
+ switchport port-security
493
+ switchport port-security maximum 1
494
+ switchport port-security mac-address sticky
495
+ switchport port-security violation shutdown
350
496
 
351
- imagestring($img, 5, 180, 300, "Shapes Demo", $black);
497
+ Final Understanding:
498
+ Before ACL everyone allowed
499
+ ACL allows only trusted IP
500
+ Spoofing bypasses security
501
+ uRPF blocks spoofed packets
352
502
 
353
- header("Content-Type: image/png");
354
- imagepng($img);
355
- imagedestroy($img);
503
+ Conclusion:
504
+ IP-based trust is not secure and must be verified using mechanisms like uRPF and port security
356
505
 
506
+ Result:
507
+ Attack simulated successfully
508
+ Vulnerability identified
509
+ Security measures implemented
357
510
 
358
- ---
359
511
 
360
512
 
361
513
 
@@ -378,528 +530,331 @@ imagedestroy($img);
378
530
 
379
531
 
380
532
 
533
+ AIM:
534
+ To allow normal UDP communication and block unwanted UDP traffic using ACL.
381
535
 
536
+ Step 1: Build the Network
537
+ Devices required:
538
+ 1 Router (2911)
539
+ 1 Switch (2960)
540
+ PC1 (Client)
541
+ PC2 (Attacker)
542
+ 1 Server
382
543
 
544
+ Connections:
545
+ PC1 FastEthernet0 to Switch Fa0/1
546
+ PC2 FastEthernet0 to Switch Fa0/2
547
+ Server FastEthernet0 to Switch Fa0/3
548
+ Switch Fa0/24 to Router GigabitEthernet0/0
383
549
 
550
+ Step 2: IP Configuration
551
+ PC1 IP 192.168.1.10 Gateway 192.168.1.1
552
+ PC2 IP 192.168.1.30 Gateway 192.168.1.1
553
+ Server IP 192.168.1.20
554
+ Subnet Mask 255.255.255.0
384
555
 
556
+ Step 3: Configure Router
557
+ enable
558
+ configure terminal
559
+ interface g0/0
560
+ ip address 192.168.1.1 255.255.255.0
561
+ no shutdown
562
+ exit
385
563
 
564
+ Step 4: Enable UDP Service on Server
565
+ Open Server -> Services -> DNS
566
+ Turn DNS ON
567
+ Add entry:
568
+ Name example.com
569
+ Address 192.168.1.20
386
570
 
571
+ Step 5: Test UDP Communication
572
+ From PC1:
573
+ nslookup example.com 192.168.1.20
574
+ UDP communication should work
387
575
 
388
- ---
576
+ Step 6: Apply ACL to Block Attacker
577
+ Router(config)# access-list 100 deny udp host 192.168.1.30 any
578
+ Router(config)# access-list 100 permit ip any any
389
579
 
390
- ## 1. Right Triangle
580
+ Apply ACL:
581
+ interface g0/0
582
+ ip access-group 100 in
583
+ exit
391
584
 
392
- **Pattern:**
585
+ Step 7: Test After ACL
586
+ From PC2:
587
+ nslookup example.com 192.168.1.20 (should fail)
393
588
 
394
- ```
395
- *
396
- * *
397
- * * *
398
- * * * *
399
- * * * * *
400
- ```
589
+ From PC1:
590
+ nslookup example.com 192.168.1.20 (should work)
401
591
 
402
- **Code:**
403
-
404
- ```php
405
- <?php
406
- for($i = 1; $i <= 5; $i++){
407
- for($j = 1; $j <= $i; $j++){
408
- echo "* ";
409
- }
410
- echo "<br>";
411
- }
412
- ?>
413
- ```
592
+ Step 8: Block DNS Service (Port-Based ACL)
593
+ Router(config)# access-list 101 deny udp any any eq 53
594
+ Router(config)# access-list 101 permit ip any any
414
595
 
415
- ---
596
+ Apply:
597
+ interface g0/0
598
+ ip access-group 101 in
599
+ exit
416
600
 
417
- ## 2. Inverted Triangle
601
+ Test:
602
+ From PC1:
603
+ nslookup example.com 192.168.1.20 (should fail)
418
604
 
419
- **Pattern:**
605
+ Step 9: Important Concept
606
+ If all devices are in same network, traffic bypasses router
607
+ Communication becomes PC -> Switch -> Server
608
+ ACL will not work
420
609
 
421
- ```
422
- * * * * *
423
- * * * *
424
- * * *
425
- * *
426
- *
427
- ```
610
+ Step 10: Fix Topology
611
+ Change Server network:
612
+ Server IP 10.0.0.2 Gateway 10.0.0.1
428
613
 
429
- **Code:**
430
-
431
- ```php
432
- <?php
433
- for($i = 5; $i >= 1; $i--){
434
- for($j = 1; $j <= $i; $j++){
435
- echo "* ";
436
- }
437
- echo "<br>";
438
- }
439
- ?>
440
- ```
614
+ Configure Router:
615
+ interface g0/1
616
+ ip address 10.0.0.1 255.255.255.0
617
+ no shutdown
441
618
 
442
- ---
619
+ Now traffic flows through router:
620
+ PC -> Router -> Server
621
+ ACL works correctly
443
622
 
444
- ## 3. Full Pyramid
623
+ Concepts:
624
+ UDP is fast and connectionless protocol
625
+ ACL filters traffic based on rules
626
+ Port 53 is used for DNS
627
+ Router must be in path for ACL to work
445
628
 
446
- **Pattern:**
629
+ Result:
630
+ UDP communication tested
631
+ Attacker blocked using ACL
632
+ DNS service blocked using port-based ACL
633
+ Network secured successfully
447
634
 
448
- ```
449
- *
450
- ***
451
- *****
452
- *******
453
- *********
454
- ```
455
635
 
456
- **Code:**
457
-
458
- ```php
459
- <?php
460
- for($i = 1; $i <= 5; $i++){
461
- for($j = 1; $j <= 5 - $i; $j++){
462
- echo "&nbsp;";
463
- }
464
- for($k = 1; $k <= (2*$i - 1); $k++){
465
- echo "*";
466
- }
467
- echo "<br>";
468
- }
469
- ?>
470
- ```
471
636
 
472
- ---
473
637
 
474
- ## ⭐ 4. Diamond Pattern
475
638
 
476
- **Pattern:**
477
639
 
478
- ```
479
- *
480
- ***
481
- *****
482
- ***
483
- *
484
- ```
485
640
 
486
- **Code:**
487
-
488
- ```php
489
- <?php
490
- // upper
491
- for($i = 1; $i <= 3; $i++){
492
- for($j = 1; $j <= 3 - $i; $j++){
493
- echo "&nbsp;";
494
- }
495
- for($k = 1; $k <= (2*$i - 1); $k++){
496
- echo "*";
497
- }
498
- echo "<br>";
499
- }
500
-
501
- // lower
502
- for($i = 2; $i >= 1; $i--){
503
- for($j = 1; $j <= 3 - $i; $j++){
504
- echo "&nbsp;";
505
- }
506
- for($k = 1; $k <= (2*$i - 1); $k++){
507
- echo "*";
508
- }
509
- echo "<br>";
510
- }
511
- ?>
512
- ```
513
641
 
514
- ---
515
642
 
516
- ## 5. Number Triangle
517
643
 
518
- **Pattern:**
519
644
 
520
- ```
521
- 1
522
- 1 2
523
- 1 2 3
524
- 1 2 3 4
525
- 1 2 3 4 5
526
- ```
527
645
 
528
- **Code:**
529
-
530
- ```php
531
- <?php
532
- for($i = 1; $i <= 5; $i++){
533
- for($j = 1; $j <= $i; $j++){
534
- echo $j . " ";
535
- }
536
- echo "<br>";
537
- }
538
- ?>
539
- ```
540
646
 
541
- ---
542
647
 
543
- ## 6. Floyd’s Triangle
544
648
 
545
- **Pattern:**
546
649
 
547
- ```
548
- 1
549
- 2 3
550
- 4 5 6
551
- 7 8 9 10
552
- ```
553
650
 
554
- **Code:**
555
-
556
- ```php
557
- <?php
558
- $num = 1;
559
- for($i = 1; $i <= 4; $i++){
560
- for($j = 1; $j <= $i; $j++){
561
- echo $num . " ";
562
- $num++;
563
- }
564
- echo "<br>";
565
- }
566
- ?>
567
- ```
568
651
 
569
- ---
570
652
 
571
- ## 7. Alphabet Pattern
572
653
 
573
- **Pattern:**
574
654
 
575
- ```
576
- A
577
- A B
578
- A B C
579
- A B C D
580
- ```
581
655
 
582
- **Code:**
583
-
584
- ```php
585
- <?php
586
- for($i = 65; $i <= 68; $i++){
587
- for($j = 65; $j <= $i; $j++){
588
- echo chr($j) . " ";
589
- }
590
- echo "<br>";
591
- }
592
- ?>
593
- ```
594
656
 
595
- ---
657
+ AIM:
658
+ Create a network, enable DNS (UDP), allow normal user, and block attacker using ACL.
596
659
 
597
- ## 8. Hollow Square
660
+ Step 1: Topology
661
+ PC1 (Client) and PC2 (Attacker) connected to Switch
662
+ Switch connected to Router G0/0
663
+ Router G0/1 connected to Server
598
664
 
599
- **Pattern:**
665
+ Step 2: Connections
666
+ Use Copper Straight-Through cables
667
+ PC1 to Switch Fa0/1
668
+ PC2 to Switch Fa0/2
669
+ Switch to Router G0/0
670
+ Router G0/1 to Server
671
+ All links should be active
600
672
 
601
- ```
602
- * * * * *
603
- * *
604
- * *
605
- * *
606
- * * * * *
607
- ```
673
+ Step 3: IP Configuration
674
+ PC1 IP 192.168.1.10 Mask 255.255.255.0 Gateway 192.168.1.1 DNS 10.0.0.2
675
+ PC2 IP 192.168.1.30 Mask 255.255.255.0 Gateway 192.168.1.1 DNS 10.0.0.2
676
+ Server IP 10.0.0.2 Mask 255.255.255.0 Gateway 10.0.0.1
608
677
 
609
- **Code:**
610
-
611
- ```php
612
- <?php
613
- $n = 5;
614
- for($i = 1; $i <= $n; $i++){
615
- for($j = 1; $j <= $n; $j++){
616
- if($i == 1 || $i == $n || $j == 1 || $j == $n){
617
- echo "* ";
618
- } else {
619
- echo "&nbsp;&nbsp;";
620
- }
621
- }
622
- echo "<br>";
623
- }
624
- ?>
625
- ```
678
+ Step 4: Router Configuration
679
+ enable
680
+ configure terminal
626
681
 
627
- ---
628
- ---
682
+ interface g0/0
683
+ ip address 192.168.1.1 255.255.255.0
684
+ no shutdown
685
+ exit
629
686
 
630
- ## 9. Left-Aligned Triangle
687
+ interface g0/1
688
+ ip address 10.0.0.1 255.255.255.0
689
+ no shutdown
690
+ exit
631
691
 
632
- **Pattern:**
692
+ Step 5: Enable DNS on Server
693
+ Open Server -> Services -> DNS
694
+ Turn DNS ON
695
+ Add entry:
696
+ Name example.com
697
+ Address 10.0.0.2
633
698
 
634
- ```
635
- *
636
- * *
637
- * * *
638
- * * * *
639
- * * * * *
640
- ```
699
+ Step 6: Initial Testing
700
+ From PC1:
701
+ ping 10.0.0.2
702
+ This builds ARP
641
703
 
642
- **Code:**
643
-
644
- ```php
645
- <?php
646
- for($i = 1; $i <= 5; $i++){
647
- for($j = 1; $j <= 5 - $i; $j++){
648
- echo "&nbsp;&nbsp;";
649
- }
650
- for($k = 1; $k <= $i; $k++){
651
- echo "* ";
652
- }
653
- echo "<br>";
654
- }
655
- ?>
656
- ```
704
+ Then:
705
+ nslookup example.com
706
+ Should work successfully
657
707
 
658
- ---
708
+ Step 7: Apply ACL Security
709
+ configure terminal
659
710
 
660
- ## 10. Hollow Pyramid
711
+ access-list 101 deny udp host 192.168.1.30 any
712
+ access-list 101 permit ip any any
661
713
 
662
- **Pattern:**
714
+ interface g0/0
715
+ ip access-group 101 in
716
+ exit
663
717
 
664
- ```
665
- *
666
- * *
667
- * *
668
- * *
669
- *********
670
- ```
718
+ Step 8: Final Testing
719
+ From PC1:
720
+ nslookup example.com
721
+ Should work
671
722
 
672
- **Code:**
673
-
674
- ```php
675
- <?php
676
- $n = 5;
677
- for($i = 1; $i <= $n; $i++){
678
- for($j = 1; $j <= $n - $i; $j++){
679
- echo "&nbsp;&nbsp;";
680
- }
681
- for($k = 1; $k <= (2*$i - 1); $k++){
682
- if($k == 1 || $k == (2*$i - 1) || $i == $n){
683
- echo "*";
684
- } else {
685
- echo "&nbsp;";
686
- }
687
- }
688
- echo "<br>";
689
- }
690
- ?>
691
- ```
723
+ From PC2:
724
+ nslookup example.com
725
+ Should fail
692
726
 
693
- ---
727
+ Concepts:
728
+ Router must be in path for ACL to work
729
+ DNS uses UDP port 53
730
+ First ping builds ARP and avoids timeout
731
+ ACL filters traffic based on rules
694
732
 
695
- ## ⭐ 11. Hollow Diamond
733
+ Final Result:
734
+ PC1 allowed
735
+ PC2 blocked
736
+ DNS working
737
+ ACL applied successfully
696
738
 
697
- **Pattern:**
698
739
 
699
- ```
700
- *
701
- * *
702
- * *
703
- * *
704
- *
705
- ```
706
740
 
707
- **Code:**
708
-
709
- ```php
710
- <?php
711
- $n = 3;
712
-
713
- // upper
714
- for($i = 1; $i <= $n; $i++){
715
- for($j = 1; $j <= $n - $i; $j++){
716
- echo "&nbsp;&nbsp;";
717
- }
718
- for($k = 1; $k <= (2*$i - 1); $k++){
719
- if($k == 1 || $k == (2*$i - 1)){
720
- echo "*";
721
- } else {
722
- echo "&nbsp;";
723
- }
724
- }
725
- echo "<br>";
726
- }
727
-
728
- // lower
729
- for($i = $n - 1; $i >= 1; $i--){
730
- for($j = 1; $j <= $n - $i; $j++){
731
- echo "&nbsp;&nbsp;";
732
- }
733
- for($k = 1; $k <= (2*$i - 1); $k++){
734
- if($k == 1 || $k == (2*$i - 1)){
735
- echo "*";
736
- } else {
737
- echo "&nbsp;";
738
- }
739
- }
740
- echo "<br>";
741
- }
742
- ?>
743
- ```
744
741
 
745
- ---
746
742
 
747
- ## 12. Palindrome Number Pattern
748
743
 
749
- **Pattern:**
750
744
 
751
- ```
752
- 1
753
- 121
754
- 12321
755
- 1234321
756
- ```
757
745
 
758
- **Code:**
759
-
760
- ```php
761
- <?php
762
- for($i = 1; $i <= 4; $i++){
763
- for($j = 1; $j <= $i; $j++){
764
- echo $j;
765
- }
766
- for($j = $i - 1; $j >= 1; $j--){
767
- echo $j;
768
- }
769
- echo "<br>";
770
- }
771
- ?>
772
- ```
773
746
 
774
- ---
775
747
 
776
- ## 13. Pascal’s Triangle
777
748
 
778
- **Pattern:**
779
749
 
780
- ```
781
- 1
782
- 1 1
783
- 1 2 1
784
- 1 3 3 1
785
- ```
786
750
 
787
- **Code:**
788
-
789
- ```php
790
- <?php
791
- $n = 5;
792
-
793
- for($i = 0; $i < $n; $i++){
794
- $num = 1;
795
- for($j = 0; $j <= $i; $j++){
796
- echo $num . " ";
797
- $num = $num * ($i - $j) / ($j + 1);
798
- }
799
- echo "<br>";
800
- }
801
- ?>
802
- ```
803
751
 
804
- ---
805
752
 
806
- ## 14. Butterfly Pattern
807
753
 
808
- **Pattern:**
809
754
 
810
- ```
811
- * *
812
- ** **
813
- *** ***
814
- ********
815
- *** ***
816
- ** **
817
- * *
818
- ```
819
755
 
820
- **Code:**
821
-
822
- ```php
823
- <?php
824
- $n = 4;
825
-
826
- // upper
827
- for($i = 1; $i <= $n; $i++){
828
- for($j = 1; $j <= $i; $j++){
829
- echo "*";
830
- }
831
- for($j = 1; $j <= 2*($n-$i); $j++){
832
- echo "&nbsp;";
833
- }
834
- for($j = 1; $j <= $i; $j++){
835
- echo "*";
836
- }
837
- echo "<br>";
838
- }
839
-
840
- // lower
841
- for($i = $n; $i >= 1; $i--){
842
- for($j = 1; $j <= $i; $j++){
843
- echo "*";
844
- }
845
- for($j = 1; $j <= 2*($n-$i); $j++){
846
- echo "&nbsp;";
847
- }
848
- for($j = 1; $j <= $i; $j++){
849
- echo "*";
850
- }
851
- echo "<br>";
852
- }
853
- ?>
854
- ```
855
756
 
856
- ---
857
757
 
858
- ## 15. Reverse Alphabet Pattern
859
758
 
860
- **Pattern:**
861
759
 
862
- ```
863
- E
864
- D E
865
- C D E
866
- B C D E
867
- A B C D E
868
- ```
869
760
 
870
- **Code:**
871
-
872
- ```php
873
- <?php
874
- for($i = 69; $i >= 65; $i--){
875
- for($j = $i; $j <= 69; $j++){
876
- echo chr($j) . " ";
877
- }
878
- echo "<br>";
879
- }
880
- ?>
881
- ```
882
761
 
883
- ---
884
762
 
885
763
 
886
764
 
887
765
 
888
766
 
767
+ AIM:
768
+ Simulate a DNS-based UDP hijacking scenario, observe its impact on the client, and apply basic protection.
889
769
 
770
+ Step 1: Topology Setup
771
+ Connect devices using Copper Straight-Through:
772
+ PC1 to Switch
773
+ PC2 to Switch
774
+ Server to Switch
775
+ Switch to Router
776
+ Ensure all connections are active
890
777
 
778
+ Step 2: IP Configuration
779
+ PC1 IP 192.168.1.10 Mask 255.255.255.0 Gateway 192.168.1.1 DNS 192.168.1.100
780
+ PC2 IP 192.168.1.20 Gateway 192.168.1.1
781
+ Server IP 192.168.1.100 Gateway 192.168.1.1
891
782
 
783
+ Step 3: Router Configuration
784
+ enable
785
+ configure terminal
786
+ interface g0/0
787
+ ip address 192.168.1.1 255.255.255.0
788
+ no shutdown
789
+ exit
892
790
 
791
+ Step 4: Enable DNS on Real Server
792
+ Open Server -> Services -> DNS
793
+ Turn DNS ON
794
+ Add entry:
795
+ example.com maps to 192.168.1.100
893
796
 
797
+ Step 5: Test Normal Output
798
+ From PC1:
799
+ nslookup example.com
800
+ Expected result:
801
+ Name example.com
802
+ Address 192.168.1.100
894
803
 
804
+ Step 6: Simulate Attack
805
+ Turn OFF real server
806
+ On PC2 change IP to 192.168.1.100
807
+ Enable DNS on PC2
808
+ Add entry:
809
+ example.com maps to 5.5.5.5
895
810
 
811
+ Step 7: Test Attack Output
812
+ From PC1:
813
+ nslookup example.com
814
+ Expected result:
815
+ Name example.com
816
+ Address 5.5.5.5
896
817
 
818
+ Observation:
819
+ Before attack DNS resolves to 192.168.1.100
820
+ After attack DNS resolves to 5.5.5.5
821
+ Client is misled
897
822
 
823
+ Step 8: Apply Basic Protection using Port Security
824
+ On Switch CLI:
825
+ enable
826
+ configure terminal
827
+ interface fa0/2
828
+ switchport mode access
829
+ switchport port-security
830
+ switchport port-security maximum 1
831
+ switchport port-security mac-address sticky
832
+ switchport port-security violation shutdown
833
+ exit
898
834
 
835
+ Step 9: Final Check
836
+ Attempt attack again
837
+ Port security blocks attacker or shuts down port
899
838
 
839
+ Output Observation Methods:
840
+ Command Line:
841
+ Use nslookup example.com before and after attack
900
842
 
843
+ Simulation Mode:
844
+ Select Simulation
845
+ Filter DNS or UDP
846
+ Run nslookup
847
+ Observe source IP, destination IP, and UDP port 53
901
848
 
849
+ Conclusion:
850
+ DNS over UDP can be exploited by spoofing
851
+ Client blindly trusts DNS response
852
+ Security measures like port security help prevent attacks
902
853
 
854
+ Result:
855
+ Attack successfully simulated
856
+ Impact observed
857
+ Basic protection applied
903
858
 
904
859
 
905
860
 
@@ -908,467 +863,164 @@ for($i = 69; $i >= 65; $i--){
908
863
 
909
864
 
910
865
 
911
- ---
912
866
 
913
- ## 1. Current Date & Time (Using `date()`)
914
867
 
915
- ```php
916
- <?php
917
- date_default_timezone_set("Asia/Kolkata");
918
868
 
919
- echo "Current Date: " . date("Y-m-d") . "<br>";
920
- echo "Current Time: " . date("H:i:s") . "<br>";
921
- echo "Full Format: " . date("d-m-Y H:i:s");
922
- ?>
923
- ```
924
869
 
925
- ### Common Formats
926
870
 
927
- * `Y` → year (2026)
928
- * `m` → month
929
- * `d` → day
930
- * `H` → hour (24 format)
931
- * `i` → minutes
932
- * `s` → seconds
933
871
 
934
- ---
935
872
 
936
- ## 2. Using `time()` (Timestamp)
937
873
 
938
- ```php
939
- <?php
940
- date_default_timezone_set("Asia/Kolkata");
941
874
 
942
- $current = time();
943
875
 
944
- echo "Timestamp: " . $current . "<br>";
945
- echo "Readable Date: " . date("d-m-Y H:i:s", $current);
946
- ?>
947
- ```
948
876
 
949
- ---
950
877
 
951
- ## 3. Using `new DateTime()` (IMPORTANT)
952
878
 
953
- This is the **modern and most important method**.
954
879
 
955
- ```php
956
- <?php
957
- date_default_timezone_set("Asia/Kolkata");
958
880
 
959
- $date = new DateTime();
960
881
 
961
- echo $date->format("d-m-Y H:i:s");
962
- ?>
963
- ```
964
882
 
965
- ---
966
883
 
967
- ## 4. Custom Date
968
884
 
969
- ```php
970
- <?php
971
- $date = new DateTime("2026-04-02");
972
885
 
973
- echo $date->format("d-m-Y");
974
- ?>
975
- ```
976
886
 
977
- ---
978
887
 
979
- ## 5. Add / Modify Date
980
888
 
981
- ```php
982
- <?php
983
- $date = new DateTime();
984
889
 
985
- $date->modify("+5 days");
986
- echo "After 5 days: " . $date->format("d-m-Y") . "<br>";
987
890
 
988
- $date->modify("+1 month");
989
- echo "After 1 month: " . $date->format("d-m-Y");
990
- ?>
991
- ```
891
+ AIM:
892
+ Simulate a DoS condition using continuous requests, observe its impact on a server, and apply prevention techniques.
992
893
 
993
- ---
994
-
995
- ## 6. Date Difference (Age Calculator Logic)
996
-
997
- ```php
998
- <?php
999
- date_default_timezone_set("Asia/Kolkata");
1000
-
1001
- $birth = new DateTime("2006-01-03");
1002
- $current = new DateTime();
1003
-
1004
- $diff = $current->diff($birth);
1005
-
1006
- echo "Age: " . $diff->y . " Years ";
1007
- echo $diff->m . " Months ";
1008
- echo $diff->d . " Days";
1009
- ?>
1010
- ```
1011
-
1012
- ---
1013
-
1014
- ## 7. Compare Two Dates
1015
-
1016
- ```php
1017
- <?php
1018
- $d1 = new DateTime("2026-04-01");
1019
- $d2 = new DateTime("2026-04-10");
894
+ Step 1: Topology
895
+ Devices:
896
+ PC1, PC2, PC3, Server connected to Switch
897
+ Switch connected to Router G0/0
898
+ Ensure all connections are active
1020
899
 
1021
- if($d1 < $d2){
1022
- echo "d1 is earlier";
1023
- } else {
1024
- echo "d2 is earlier";
1025
- }
1026
- ?>
1027
- ```
1028
-
1029
- ---
900
+ Step 2: IP Configuration
901
+ PC1 IP 192.168.1.10
902
+ PC2 IP 192.168.1.20
903
+ PC3 IP 192.168.1.30
904
+ Server IP 192.168.1.100
905
+ Mask 255.255.255.0
906
+ Gateway 192.168.1.1
1030
907
 
1031
- ## Important Exam Points
908
+ Step 3: Router Configuration
909
+ enable
910
+ configure terminal
911
+ interface g0/0
912
+ ip address 192.168.1.1 255.255.255.0
913
+ no shutdown
914
+ exit
1032
915
 
1033
- * Always use:
916
+ Step 4: Enable Server Service
917
+ Open Server -> Services -> HTTP
918
+ Turn HTTP ON
1034
919
 
1035
- ```php
1036
- date_default_timezone_set("Asia/Kolkata");
1037
- ```
920
+ Step 5: Normal Test
921
+ From PC1:
922
+ ping 192.168.1.100
923
+ Stable replies indicate normal operation
1038
924
 
925
+ Step 6: Simulate DoS Attack
926
+ From PC2:
927
+ ping 192.168.1.100 -t
1039
928
 
929
+ From PC3:
930
+ ping 192.168.1.100 -t
1040
931
 
932
+ Continuous traffic is generated
1041
933
 
934
+ Step 7: Observe Impact
935
+ From PC1:
936
+ ping 192.168.1.100
1042
937
 
938
+ Expected results:
939
+ Request timed out
940
+ High delay
941
+ Packet loss
1043
942
 
943
+ Indicates server overload and network congestion
1044
944
 
945
+ Step 8: Important Concept
946
+ If all devices are in same network, traffic flows directly
947
+ PC -> Switch -> Server
948
+ Router is bypassed
949
+ ACL on router will not work
1045
950
 
951
+ Step 9: Apply Switch Port Security
952
+ enable
953
+ configure terminal
1046
954
 
955
+ interface fa0/2
956
+ switchport port-security
957
+ switchport port-security maximum 1
958
+ switchport port-security violation shutdown
959
+ exit
1047
960
 
961
+ interface fa0/3
962
+ switchport port-security
963
+ switchport port-security maximum 1
964
+ switchport port-security violation shutdown
965
+ exit
1048
966
 
967
+ Limits attacker behavior
1049
968
 
969
+ Step 10: Improved Topology for Router Control
970
+ Change Server network:
971
+ Server IP 10.0.0.2 Gateway 10.0.0.1
1050
972
 
973
+ Add router interface:
974
+ interface g0/1
975
+ ip address 10.0.0.1 255.255.255.0
976
+ no shutdown
1051
977
 
978
+ Traffic now passes through router
1052
979
 
980
+ Step 11: Apply ACL Protection
981
+ ip access-list extended BLOCK_ICMP
982
+ permit icmp host 192.168.1.10 host 10.0.0.2
983
+ deny icmp any any
1053
984
 
985
+ interface g0/0
986
+ ip access-group BLOCK_ICMP in
1054
987
 
988
+ Step 12: Final Testing
989
+ From PC1:
990
+ ping 10.0.0.2 (should work)
1055
991
 
992
+ From PC2 and PC3:
993
+ ping 10.0.0.2 (should fail)
1056
994
 
995
+ Output Observation:
996
+ Command Line:
997
+ Compare ping before and during attack
1057
998
 
999
+ Simulation Mode:
1000
+ Filter ICMP
1001
+ Observe multiple packets and congestion
1058
1002
 
1003
+ Conclusion:
1004
+ DoS attack floods server with requests causing delay and packet loss
1005
+ Switch port security and ACL help control traffic
1059
1006
 
1007
+ Result:
1008
+ Attack simulated
1009
+ Impact observed
1010
+ Protection applied successfully
1060
1011
 
1061
1012
 
1062
1013
 
1063
1014
 
1064
1015
 
1065
1016
 
1066
- ## **1. HTML Form + Display Name using PHP**
1067
1017
 
1068
- ```php
1069
- <!-- form.php -->
1070
- <form method="post">
1071
- Enter Name: <input type="text" name="username">
1072
- <input type="submit" value="Submit">
1073
- </form>
1074
1018
 
1075
- <?php
1076
- if(isset($_POST['username'])){
1077
- echo "Hello " . $_POST['username'];
1078
- }
1079
- ?>
1080
- ```
1081
1019
 
1082
- ---
1083
1020
 
1084
- ## **2. Number Programs**
1085
1021
 
1086
- ### **(a) Prime Number**
1087
1022
 
1088
- ```php
1089
- <?php
1090
- $num = 7;
1091
- $flag = 1;
1092
1023
 
1093
- for($i=2; $i<$num; $i++){
1094
- if($num % $i == 0){
1095
- $flag = 0;
1096
- break;
1097
- }
1098
- }
1099
1024
 
1100
- if($flag == 1)
1101
- echo "Prime";
1102
- else
1103
- echo "Not Prime";
1104
- ?>
1105
- ```
1106
-
1107
- ### **(b) Odd or Even**
1108
-
1109
- ```php
1110
- <?php
1111
- $num = 10;
1112
-
1113
- if($num % 2 == 0)
1114
- echo "Even";
1115
- else
1116
- echo "Odd";
1117
- ?>
1118
- ```
1119
-
1120
- ### **(c) Greatest of Three Numbers**
1121
-
1122
- ```php
1123
- <?php
1124
- $a = 10; $b = 25; $c = 15;
1125
-
1126
- if($a >= $b && $a >= $c)
1127
- echo "Greatest: $a";
1128
- elseif($b >= $a && $b >= $c)
1129
- echo "Greatest: $b";
1130
- else
1131
- echo "Greatest: $c";
1132
- ?>
1133
- ```
1134
-
1135
- ---
1136
-
1137
- ## **3. Loop Programs**
1138
-
1139
- ### **(a) Reverse 10 to 1**
1140
-
1141
- ```php
1142
- <?php
1143
- for($i=10; $i>=1; $i--){
1144
- echo $i . " ";
1145
- }
1146
- ?>
1147
- ```
1148
-
1149
- ### **(b) 1-2-3-...-10 (no extra hyphen)**
1150
-
1151
- ```php
1152
- <?php
1153
- for($i=1; $i<=10; $i++){
1154
- if($i < 10)
1155
- echo $i . "-";
1156
- else
1157
- echo $i;
1158
- }
1159
- ?>
1160
- ```
1161
-
1162
- ### **(c) Floyd Triangle**
1163
-
1164
- ```php
1165
- <?php
1166
- $n = 5;
1167
- $num = 1;
1168
-
1169
- for($i=1; $i<=$n; $i++){
1170
- for($j=1; $j<=$i; $j++){
1171
- echo $num . " ";
1172
- $num++;
1173
- }
1174
- echo "<br>";
1175
- }
1176
- ?>
1177
- ```
1178
-
1179
- ---
1180
-
1181
- ## **4. Continue + Arithmetic Operations**
1182
-
1183
- ### **(a) Skip User Number**
1184
-
1185
- ```php
1186
- <?php
1187
- $skip = 5;
1188
-
1189
- for($i=1; $i<=10; $i++){
1190
- if($i == $skip)
1191
- continue;
1192
- echo $i . " ";
1193
- }
1194
- ?>
1195
- ```
1196
1025
 
1197
- ### **(b) Arithmetic using Select Box**
1198
-
1199
- ```php
1200
- <form method="post">
1201
- Num1: <input type="number" name="a"><br>
1202
- Num2: <input type="number" name="b"><br>
1203
- <select name="op">
1204
- <option value="add">Add</option>
1205
- <option value="sub">Subtract</option>
1206
- <option value="mul">Multiply</option>
1207
- <option value="div">Divide</option>
1208
- </select>
1209
- <input type="submit">
1210
- </form>
1211
-
1212
- <?php
1213
- if(isset($_POST['op'])){
1214
- $a = $_POST['a'];
1215
- $b = $_POST['b'];
1216
-
1217
- if($_POST['op']=="add") echo $a+$b;
1218
- elseif($_POST['op']=="sub") echo $a-$b;
1219
- elseif($_POST['op']=="mul") echo $a*$b;
1220
- elseif($_POST['op']=="div") echo $a/$b;
1221
- }
1222
- ?>
1223
- ```
1224
-
1225
- ---
1226
-
1227
- ## **5. Table + Armstrong**
1228
-
1229
- ### **(a) Multiplication Table**
1230
-
1231
- ```php
1232
- <?php
1233
- $num = 5;
1234
-
1235
- for($i=1; $i<=10; $i++){
1236
- echo "$num x $i = " . ($num*$i) . "<br>";
1237
- }
1238
- ?>
1239
- ```
1240
-
1241
- ### **(b) Armstrong Number**
1242
-
1243
- ```php
1244
- <?php
1245
- $num = 153;
1246
- $sum = 0;
1247
- $temp = $num;
1248
-
1249
- while($temp > 0){
1250
- $rem = $temp % 10;
1251
- $sum += $rem * $rem * $rem;
1252
- $temp = (int)($temp/10);
1253
- }
1254
-
1255
- if($sum == $num)
1256
- echo "Armstrong";
1257
- else
1258
- echo "Not Armstrong";
1259
- ?>
1260
- ```
1261
-
1262
- ---
1263
-
1264
- ## **6. Array + Table**
1265
-
1266
- ### **(a) Fruit Table**
1267
-
1268
- ```php
1269
- <?php
1270
- $fruits = ["Apple", "Banana", "Mango"];
1271
-
1272
- echo "<table border=1>";
1273
- foreach($fruits as $f){
1274
- echo "<tr><td>$f</td></tr>";
1275
- }
1276
- echo "</table>";
1277
- ?>
1278
- ```
1279
-
1280
- ### **(b) Sum of Array**
1281
-
1282
- ```php
1283
- <?php
1284
- $arr = [1,2,3,4,5];
1285
- $sum = 0;
1286
-
1287
- foreach($arr as $v){
1288
- $sum += $v;
1289
- }
1290
-
1291
- echo "Sum = $sum";
1292
- ?>
1293
- ```
1294
-
1295
- ---
1296
-
1297
- ## **7 & 8. Matrix + Palindrome**
1298
-
1299
- ### **(a) Multiply Number with Matrix**
1300
-
1301
- ```php
1302
- <?php
1303
- $matrix = [
1304
- [1,2],
1305
- [3,4]
1306
- ];
1307
-
1308
- $num = 2;
1309
-
1310
- for($i=0; $i<2; $i++){
1311
- for($j=0; $j<2; $j++){
1312
- echo $matrix[$i][$j] * $num . " ";
1313
- }
1314
- echo "<br>";
1315
- }
1316
- ?>
1317
- ```
1318
-
1319
- ### **(b) Palindrome String**
1320
-
1321
- ```php
1322
- <?php
1323
- $str = "malayalam";
1324
-
1325
- if($str == strrev($str))
1326
- echo "Palindrome";
1327
- else
1328
- echo "Not Palindrome";
1329
- ?>
1330
- ```
1331
-
1332
- ---
1333
-
1334
- ## **9. Registration Form + Display Data**
1335
-
1336
- ```php
1337
- <form method="post">
1338
- Name: <input type="text" name="name"><br>
1339
- Email: <input type="text" name="email"><br>
1340
- <input type="submit">
1341
- </form>
1342
-
1343
- <?php
1344
- if(isset($_POST['name'])){
1345
- echo "Name: " . $_POST['name'] . "<br>";
1346
- echo "Email: " . $_POST['email'];
1347
- }
1348
- ?>
1349
- ```
1350
-
1351
- ---
1352
-
1353
- ## **10. Login (Username + Password Check)**
1354
-
1355
- ```php
1356
- <form method="post">
1357
- Username: <input type="text" name="user"><br>
1358
- Password: <input type="password" name="pass"><br>
1359
- <input type="submit">
1360
- </form>
1361
-
1362
- <?php
1363
- if(isset($_POST['user'])){
1364
- if($_POST['user']=="admin" && $_POST['pass']=="godsgift"){
1365
- echo "Welcome Admin";
1366
- } else {
1367
- echo "Invalid Login";
1368
- header("refresh:2; url=");
1369
- }
1370
- }
1371
- ?>
1372
- ```
1373
1026
 
1374
- ---