chiwormjava 2.0.2 → 2.0.3

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 +156 -1185
package/readme.md CHANGED
@@ -42,1333 +42,304 @@ 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
- ---
54
-
55
- ## 📸 Features
56
-
57
- * 📚 Java DSA snippets (LinkedList, etc.)
58
- * 🖱️ One-click code view
59
- * 📋 Copy to clipboard
60
- * 🌙 Clean dark UI
61
-
62
- ---
63
-
64
- ## ▶️ Usage
65
-
66
- After running the command:
67
-
68
- ```bash
69
- javacodewatch
70
- ```
71
-
72
- 👉 Your browser will open automatically:
73
-
74
- ```
75
- http://localhost:3000
76
- ```
77
-
78
- ---
79
-
80
- Armstrong
81
-
82
- <?php
83
- $num = 153;
84
-
85
- $temp = $num;
86
- $sum = 0;
87
-
88
- // Count number of digits
89
- $digits = strlen($num);
90
-
91
- while ($temp > 0) {
92
- $rem = $temp % 10;
93
- $sum += pow($rem, $digits);
94
- $temp = (int)($temp / 10);
95
- }
96
-
97
-
98
- if ($sum == $num) {
99
- echo "$num is an Armstrong number";
100
- } else {
101
- echo "$num is not an Armstrong number";
102
- }
103
- ?>
104
-
105
- ---
106
-
107
- <?php
108
- $img = imagecreatetruecolor(500, 350);
109
-
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);
116
-
117
- imagefill($img, 0, 0, $white);
118
-
119
- imagerectangle($img, 20, 20, 120, 100, $black);
120
-
121
- imagefilledrectangle($img, 140, 20, 240, 100, $green);
122
-
123
- imageellipse($img, 350, 70, 80, 80, $red);
124
-
125
- imagefilledellipse($img, 450, 70, 80, 80, $yellow);
126
-
127
- imageline($img, 20, 150, 200, 250, $blue);
128
-
129
- $points = array(300,150, 350,250, 250,250);
130
- imagepolygon($img, $points, 3, $black);
131
-
132
- $points2 = array(400,150, 450,250, 350,250);
133
- imagefilledpolygon($img, $points2, 3, $red);
134
-
135
- imagearc($img, 100, 300, 100, 50, 0, 180, $blue);
136
-
137
- imagestring($img, 5, 180, 300, "Shapes Demo", $black);
138
-
139
- header("Content-Type: image/png");
140
- imagepng($img);
141
-
142
- imagedestroy($img);
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
- <?php
187
- // CONNECT
188
- $conn = mysqli_connect("localhost","root","");
189
-
190
- if(!$conn){
191
- die("Connection Failed");
192
- }
193
-
194
- // CREATE DB
195
- mysqli_query($conn, "CREATE DATABASE IF NOT EXISTS testdb");
196
-
197
- // SELECT DB
198
- mysqli_select_db($conn, "testdb");
199
-
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
- )");
206
-
207
- // INSERT
208
- if(isset($_POST['add'])){
209
- $name = $_POST['name'];
210
- $email = $_POST['email'];
211
-
212
- mysqli_query($conn,"INSERT INTO student(name,email) VALUES('$name','$email')");
213
- }
214
-
215
- // DELETE
216
- if(isset($_GET['delete'])){
217
- $id = $_GET['delete'];
218
- mysqli_query($conn,"DELETE FROM student WHERE id=$id");
219
- }
220
-
221
- // UPDATE
222
- if(isset($_POST['update'])){
223
- $id = $_POST['id'];
224
- $name = $_POST['name'];
225
- $email = $_POST['email'];
226
-
227
- mysqli_query($conn,"UPDATE student SET name='$name', email='$email' WHERE id=$id");
228
- }
229
-
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
- ?>
238
-
239
- <!DOCTYPE html>
240
- <html>
241
- <body>
242
-
243
- <h2>Student Form</h2>
244
-
245
- <form method="post">
246
- <input type="hidden" name="id" value="<?php echo $editData['id'] ?? ''; ?>">
247
-
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>
250
-
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>
257
-
258
- <hr>
259
-
260
- <h2>Student Data</h2>
261
-
262
- <table border="1">
263
- <tr>
264
- <th>ID</th>
265
- <th>Name</th>
266
- <th>Email</th>
267
- <th>Action</th>
268
- </tr>
269
-
270
- <?php
271
- $result = mysqli_query($conn,"SELECT * FROM student");
272
-
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
-
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
- $img = imagecreatetruecolor(500, 350);
325
-
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);
332
-
333
- imagefill($img, 0, 0, $white);
334
-
335
- imagerectangle($img, 20, 20, 120, 100, $black);
336
- imagefilledrectangle($img, 140, 20, 240, 100, $green);
337
-
338
- imageellipse($img, 350, 70, 80, 80, $red);
339
- imagefilledellipse($img, 450, 70, 80, 80, $yellow);
340
-
341
- imageline($img, 20, 150, 200, 250, $blue);
342
-
343
- $points = [300,150, 350,250, 250,250];
344
- imagepolygon($img, $points, 3, $black);
345
-
346
- $points2 = [400,150, 450,250, 350,250];
347
- imagefilledpolygon($img, $points2, 3, $red);
348
-
349
- imagearc($img, 100, 300, 100, 50, 0, 180, $blue);
350
-
351
- imagestring($img, 5, 180, 300, "Shapes Demo", $black);
352
-
353
- header("Content-Type: image/png");
354
- imagepng($img);
355
- imagedestroy($img);
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
- ## 1. Right Triangle
391
-
392
- **Pattern:**
393
-
394
- ```
395
- *
396
- * *
397
- * * *
398
- * * * *
399
- * * * * *
400
- ```
401
-
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
- ```
414
-
415
45
  ---
416
46
 
417
- ## 2. Inverted Triangle
418
-
419
- **Pattern:**
47
+ ## Step 2: Add Serial Ports (MOST IMPORTANT FIX)
420
48
 
421
- ```
422
- * * * * *
423
- * * * *
424
- * * *
425
- * *
426
- *
427
- ```
428
-
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
- ```
49
+ By default, routers don’t have serial ports.
441
50
 
442
- ---
51
+ ### Do this for BOTH routers:
443
52
 
444
- ## 3. Full Pyramid
53
+ 1. Click Router → **Physical tab**
54
+ 2. Turn **Power OFF**
55
+ 3. From modules:
56
+ Drag **WIC-2T** into slot
57
+ 4. Turn **Power ON**
445
58
 
446
- **Pattern:**
59
+ Now you will see:
447
60
 
448
61
  ```
449
- *
450
- ***
451
- *****
452
- *******
453
- *********
454
- ```
455
-
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
- ?>
62
+ Serial0/0/0
63
+ Serial0/0/1
470
64
  ```
471
65
 
472
66
  ---
473
67
 
474
- ## 4. Diamond Pattern
475
-
476
- **Pattern:**
68
+ ## Step 3: Connect cables (CORRECT WAY)
477
69
 
478
- ```
479
- *
480
- ***
481
- *****
482
- ***
483
- *
484
- ```
70
+ ### LAN connections
485
71
 
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
- ```
72
+ * PC → Switch → **Copper Straight-Through**
73
+ * Switch → Router (Gig0/0 or Fa0/0) → **Copper Straight-Through**
513
74
 
514
75
  ---
515
76
 
516
- ## 5. Number Triangle
77
+ ### WAN connection (Router ↔ Router)
517
78
 
518
- **Pattern:**
519
-
520
- ```
521
- 1
522
- 1 2
523
- 1 2 3
524
- 1 2 3 4
525
- 1 2 3 4 5
526
- ```
527
-
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
- ```
79
+ * Select **Serial DCE cable**
80
+ * Router1 → `Serial0/0/0`
81
+ * Router2 → `Serial0/0/0`
540
82
 
541
83
  ---
542
84
 
543
- ## 6. Floyd’s Triangle
544
-
545
- **Pattern:**
85
+ ## Step 4: Configure Router1
546
86
 
547
- ```
548
- 1
549
- 2 3
550
- 4 5 6
551
- 7 8 9 10
552
- ```
553
-
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
-
569
- ---
87
+ Go to CLI:
570
88
 
571
- ## 7. Alphabet Pattern
572
-
573
- **Pattern:**
89
+ ```bash
90
+ enable
91
+ configure terminal
574
92
 
575
- ```
576
- A
577
- A B
578
- A B C
579
- A B C D
580
- ```
93
+ interface gigabitEthernet 0/0
94
+ ip address 192.168.1.1 255.255.255.0
95
+ no shutdown
96
+ exit
581
97
 
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
- ?>
98
+ interface serial 0/0/0
99
+ ip address 172.16.1.1 255.255.255.252
100
+ clock rate 64000
101
+ no shutdown
102
+ exit
593
103
  ```
594
104
 
595
105
  ---
596
106
 
597
- ## 8. Hollow Square
107
+ ## Step 5: Configure Router2
598
108
 
599
- **Pattern:**
109
+ ```bash
110
+ enable
111
+ configure terminal
600
112
 
601
- ```
602
- * * * * *
603
- * *
604
- * *
605
- * *
606
- * * * * *
607
- ```
113
+ interface gigabitEthernet 0/0
114
+ ip address 10.0.0.1 255.255.255.248
115
+ no shutdown
116
+ exit
608
117
 
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
- ?>
118
+ interface serial 0/0/0
119
+ ip address 172.16.1.2 255.255.255.252
120
+ no shutdown
121
+ exit
625
122
  ```
626
123
 
627
- ---
628
124
  ---
629
125
 
630
- ## 9. Left-Aligned Triangle
126
+ ## Step 6: Configure PCs
631
127
 
632
- **Pattern:**
128
+ ### Left network (Router1 side)
633
129
 
634
- ```
635
- *
636
- * *
637
- * * *
638
- * * * *
639
- * * * * *
640
- ```
130
+ * PC1
131
+ IP: `192.168.1.2`
132
+ Mask: `255.255.255.0`
133
+ Gateway: `192.168.1.1`
641
134
 
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
- ```
135
+ * PC2
136
+ IP: `192.168.1.3`
137
+ Gateway: `192.168.1.1`
657
138
 
658
139
  ---
659
140
 
660
- ## 10. Hollow Pyramid
141
+ ### Right network (Router2 side)
661
142
 
662
- **Pattern:**
143
+ * PC3
144
+ IP: `10.0.0.2`
145
+ Mask: `255.255.255.248`
146
+ Gateway: `10.0.0.1`
663
147
 
664
- ```
665
- *
666
- * *
667
- * *
668
- * *
669
- *********
670
- ```
671
-
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
- ```
148
+ * PC4
149
+ IP: `10.0.0.3`
150
+ Gateway: `10.0.0.1`
692
151
 
693
152
  ---
694
153
 
695
- ## 11. Hollow Diamond
154
+ ## Step 7: Configure Routing (VERY IMPORTANT)
696
155
 
697
- **Pattern:**
698
-
699
- ```
700
- *
701
- * *
702
- * *
703
- * *
704
- *
705
- ```
156
+ ### Router1:
706
157
 
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
- ?>
158
+ ```bash
159
+ ip route 10.0.0.0 255.255.255.248 172.16.1.2
743
160
  ```
744
161
 
745
- ---
746
-
747
- ## 12. Palindrome Number Pattern
748
-
749
- **Pattern:**
750
-
751
- ```
752
- 1
753
- 121
754
- 12321
755
- 1234321
756
- ```
162
+ ### Router2:
757
163
 
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
- ?>
164
+ ```bash
165
+ ip route 192.168.1.0 255.255.255.0 172.16.1.1
772
166
  ```
773
167
 
774
168
  ---
775
169
 
776
- ## 13. Pascal’s Triangle
170
+ ## Step 8: Verify interfaces
777
171
 
778
- **Pattern:**
779
-
780
- ```
781
- 1
782
- 1 1
783
- 1 2 1
784
- 1 3 3 1
785
- ```
172
+ Run on both routers:
786
173
 
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
- ?>
174
+ ```bash
175
+ show ip interface brief
802
176
  ```
803
177
 
804
- ---
805
-
806
- ## 14. Butterfly Pattern
807
-
808
- **Pattern:**
178
+ You MUST see:
809
179
 
810
180
  ```
811
- * *
812
- ** **
813
- *** ***
814
- ********
815
- *** ***
816
- ** **
817
- * *
181
+ up up
818
182
  ```
819
183
 
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
- ```
184
+ If not:
185
+ Use `no shutdown`
855
186
 
856
187
  ---
857
188
 
858
- ## 15. Reverse Alphabet Pattern
189
+ ## Step 9: Test connectivity
859
190
 
860
- **Pattern:**
191
+ From PC1:
861
192
 
193
+ ```bash
194
+ ping 10.0.0.2
862
195
  ```
863
- E
864
- D E
865
- C D E
866
- B C D E
867
- A B C D E
868
- ```
869
-
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
-
883
- ---
884
-
885
-
886
-
887
-
888
-
889
-
890
-
891
-
892
-
893
-
894
-
895
-
896
-
897
-
898
-
899
-
900
-
901
-
902
-
903
-
904
-
905
-
906
-
907
196
 
197
+ Expected:
908
198
 
909
-
910
-
911
- ---
912
-
913
- ## 1. Current Date & Time (Using `date()`)
914
-
915
- ```php
916
- <?php
917
- date_default_timezone_set("Asia/Kolkata");
918
-
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
199
  ```
924
-
925
- ### Common Formats
926
-
927
- * `Y` → year (2026)
928
- * `m` → month
929
- * `d` → day
930
- * `H` → hour (24 format)
931
- * `i` → minutes
932
- * `s` → seconds
933
-
934
- ---
935
-
936
- ## 2. Using `time()` (Timestamp)
937
-
938
- ```php
939
- <?php
940
- date_default_timezone_set("Asia/Kolkata");
941
-
942
- $current = time();
943
-
944
- echo "Timestamp: " . $current . "<br>";
945
- echo "Readable Date: " . date("d-m-Y H:i:s", $current);
946
- ?>
200
+ Reply from 10.0.0.2
947
201
  ```
948
202
 
949
203
  ---
950
204
 
951
- ## 3. Using `new DateTime()` (IMPORTANT)
952
-
953
- This is the **modern and most important method**.
205
+ ## Step 10: See animation (Simulation Mode)
954
206
 
955
- ```php
956
- <?php
957
- date_default_timezone_set("Asia/Kolkata");
207
+ 1. Click **Simulation**
208
+ 2. Click **Reset Simulation**
209
+ 3. Click **Edit Filters**
958
210
 
959
- $date = new DateTime();
211
+ * Select only:
960
212
 
961
- echo $date->format("d-m-Y H:i:s");
962
- ?>
963
- ```
213
+ ```
214
+ ARP
215
+ ICMP
216
+ ```
964
217
 
965
218
  ---
966
219
 
967
- ## 4. Custom Date
968
-
969
- ```php
970
- <?php
971
- $date = new DateTime("2026-04-02");
972
-
973
- echo $date->format("d-m-Y");
974
- ?>
975
- ```
976
-
977
- ---
978
-
979
- ## 5. Add / Modify Date
980
-
981
- ```php
982
- <?php
983
- $date = new DateTime();
220
+ ### Send packet
984
221
 
985
- $date->modify("+5 days");
986
- echo "After 5 days: " . $date->format("d-m-Y") . "<br>";
987
-
988
- $date->modify("+1 month");
989
- echo "After 1 month: " . $date->format("d-m-Y");
990
- ?>
991
- ```
222
+ * Click **Add Simple PDU (envelope icon)**
223
+ * Click **PC1 PC3**
992
224
 
993
225
  ---
994
226
 
995
- ## 6. Date Difference (Age Calculator Logic)
996
-
997
- ```php
998
- <?php
999
- date_default_timezone_set("Asia/Kolkata");
227
+ ### Play
1000
228
 
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
- ```
229
+ * Click play or ⏭ Capture/Forward
1011
230
 
1012
231
  ---
1013
232
 
1014
- ## 7. Compare Two Dates
233
+ ## 👀 What you should see
1015
234
 
1016
- ```php
1017
- <?php
1018
- $d1 = new DateTime("2026-04-01");
1019
- $d2 = new DateTime("2026-04-10");
235
+ Packet flow:
1020
236
 
1021
- if($d1 < $d2){
1022
- echo "d1 is earlier";
1023
- } else {
1024
- echo "d2 is earlier";
1025
- }
1026
- ?>
1027
237
  ```
1028
-
1029
- ---
1030
-
1031
- ## Important Exam Points
1032
-
1033
- * Always use:
1034
-
1035
- ```php
1036
- date_default_timezone_set("Asia/Kolkata");
238
+ PC1 → Switch1 → Router1 → Router2 → Switch2 → PC3
1037
239
  ```
1038
240
 
1039
-
1040
-
1041
-
1042
-
1043
-
1044
-
1045
-
1046
-
1047
-
1048
-
1049
-
1050
-
1051
-
1052
-
1053
-
1054
-
1055
-
1056
-
1057
-
1058
-
1059
-
1060
-
1061
-
1062
-
1063
-
1064
-
1065
-
1066
- ## **1. HTML Form + Display Name using PHP**
1067
-
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
-
1075
- <?php
1076
- if(isset($_POST['username'])){
1077
- echo "Hello " . $_POST['username'];
1078
- }
1079
- ?>
1080
- ```
241
+ * First ARP (finding MAC)
242
+ * Then ICMP (ping)
243
+ * All **green ✔**
1081
244
 
1082
245
  ---
1083
246
 
1084
- ## **2. Number Programs**
1085
-
1086
- ### **(a) Prime Number**
1087
-
1088
- ```php
1089
- <?php
1090
- $num = 7;
1091
- $flag = 1;
1092
-
1093
- for($i=2; $i<$num; $i++){
1094
- if($num % $i == 0){
1095
- $flag = 0;
1096
- break;
1097
- }
1098
- }
1099
-
1100
- if($flag == 1)
1101
- echo "Prime";
1102
- else
1103
- echo "Not Prime";
1104
- ?>
1105
- ```
1106
-
1107
- ### **(b) Odd or Even**
1108
247
 
1109
- ```php
1110
- <?php
1111
- $num = 10;
1112
248
 
1113
- if($num % 2 == 0)
1114
- echo "Even";
1115
- else
1116
- echo "Odd";
1117
- ?>
1118
- ```
1119
249
 
1120
- ### **(c) Greatest of Three Numbers**
1121
250
 
1122
- ```php
1123
- <?php
1124
- $a = 10; $b = 25; $c = 15;
1125
251
 
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
252
 
1135
- ---
1136
253
 
1137
- ## **3. Loop Programs**
1138
254
 
1139
- ### **(a) Reverse 10 to 1**
1140
255
 
1141
- ```php
1142
- <?php
1143
- for($i=10; $i>=1; $i--){
1144
- echo $i . " ";
1145
- }
1146
- ?>
1147
- ```
1148
256
 
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
257
 
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
258
 
1179
- ---
1180
259
 
1181
- ## **4. Continue + Arithmetic Operations**
1182
260
 
1183
- ### **(a) Skip User Number**
1184
261
 
1185
- ```php
1186
- <?php
1187
- $skip = 5;
1188
262
 
1189
- for($i=1; $i<=10; $i++){
1190
- if($i == $skip)
1191
- continue;
1192
- echo $i . " ";
1193
- }
1194
- ?>
1195
- ```
1196
263
 
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
264
 
1225
- ---
1226
265
 
1227
- ## **5. Table + Armstrong**
1228
266
 
1229
- ### **(a) Multiplication Table**
1230
267
 
1231
- ```php
1232
- <?php
1233
- $num = 5;
1234
268
 
1235
- for($i=1; $i<=10; $i++){
1236
- echo "$num x $i = " . ($num*$i) . "<br>";
1237
- }
1238
- ?>
1239
- ```
1240
269
 
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
270
 
1262
- ---
1263
271
 
1264
- ## **6. Array + Table**
1265
272
 
1266
- ### **(a) Fruit Table**
1267
273
 
1268
- ```php
1269
- <?php
1270
- $fruits = ["Apple", "Banana", "Mango"];
1271
274
 
1272
- echo "<table border=1>";
1273
- foreach($fruits as $f){
1274
- echo "<tr><td>$f</td></tr>";
1275
- }
1276
- echo "</table>";
1277
- ?>
1278
- ```
1279
275
 
1280
- ### **(b) Sum of Array**
1281
276
 
1282
- ```php
1283
- <?php
1284
- $arr = [1,2,3,4,5];
1285
- $sum = 0;
1286
277
 
1287
- foreach($arr as $v){
1288
- $sum += $v;
1289
- }
1290
278
 
1291
- echo "Sum = $sum";
1292
- ?>
1293
- ```
1294
279
 
1295
- ---
1296
280
 
1297
- ## **7 & 8. Matrix + Palindrome**
1298
281
 
1299
- ### **(a) Multiply Number with Matrix**
1300
282
 
1301
- ```php
1302
- <?php
1303
- $matrix = [
1304
- [1,2],
1305
- [3,4]
1306
- ];
1307
283
 
1308
- $num = 2;
1309
284
 
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
285
 
1319
- ### **(b) Palindrome String**
1320
286
 
1321
- ```php
1322
- <?php
1323
- $str = "malayalam";
1324
287
 
1325
- if($str == strrev($str))
1326
- echo "Palindrome";
1327
- else
1328
- echo "Not Palindrome";
1329
- ?>
1330
- ```
1331
288
 
1332
- ---
1333
289
 
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
290
 
1351
- ---
1352
291
 
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
- ```
292
+ Step 1: Setting Up the Topology
293
+ 1. Add Devices to the Workspace:
294
+ o Drag and drop:
295
+ 1 Router (e.g., 2911 or similar).
296
+ 1 Switch (e.g., 2960).
297
+ 3 PCs (PC-0, PC-1, PC-2).
298
+ 1 Cloud or Server (representing the internet).
299
+ Step 2: Assign IP Addresses
300
+ For Private Network (PCs and Router Internal Interface)
301
+ ● Assign Private IP Addresses to the PCs:
302
+ o PC-0: IP Address: 192.168.1.2 | Subnet Mask: 255.255.255.0 | Default Gateway:
303
+ 192.168.1.1
304
+ o PC-1: IP Address: 192.168.1.3 | Subnet Mask: 255.255.255.0 | Default Gateway:
305
+ 192.168.1.1
306
+ o PC-2: IP Address: 192.168.1.4 | Subnet Mask: 255.255.255.0 | Default Gateway:
307
+ 192.168.1.1
308
+ Step 3: Configure Router interface
309
+ 1) gig0/0
310
+ Router> enable
311
+ Router# configure terminal
312
+ Router(config)# interface gig0/0
313
+ Router(config-if)# ip address 192.168.1.1 255.255.255.0
314
+ Router(config-if)# no shutdown
315
+ 2) gig0/1
316
+ Router(config)# interface gig0/1
317
+ Router(config-if)# ip address 203.0.113.1 255.255.255.0
318
+ Router(config-if)# no shutdown
319
+ 3) Assign an IP Address to the Cloud or Server:
320
+ a. Cloud/Server IP Address: 203.0.113.2
321
+ b. Subnet Mask: 255.255.255.0
322
+ Step 4: Configure NAT on the Router
323
+ Define Inside and Outside Interfaces
324
+ Router(config)# interface gig0/0
325
+ Router(config-if)# ip nat inside
326
+ Router(config-if)# exit
327
+ Router(config)# interface gig0/1
328
+ Router(config-if)# ip nat outside
329
+ Router(config-if)# exit
330
+ Set Up PAT (Port Address Translation)
331
+ Allow multiple private IPs to share one public IP:
332
+ Router(config)# access-list 1 permit 192.168.1.0 0.0.0.255
333
+ Router(config)# ip nat inside source list 1 interface gig0/1 overload
334
+ Step 5: Configure Routing
335
+ Add a Default Route to direct traffic to the public network
336
+ Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2
337
+ Step 6: Test the Configuration
338
+ Test Internet Access from PCs
339
+ 1. Open the Command Prompt on any PC.
340
+ 2. Ping the external Cloud/Server (e.g., ping 203.0.113.2).
341
+ o If successful, NAT is working correctly.
342
+ Verify NAT Translations on the Router
343
+ On the router CLI, use the following command to see active NAT translations:
344
+ Router# show ip nat translations
1373
345
 
1374
- ---