-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathARP_RARP_Simulation.java
More file actions
65 lines (51 loc) · 2.09 KB
/
ARP_RARP_Simulation.java
File metadata and controls
65 lines (51 loc) · 2.09 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
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class ARP_RARP_Simulation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// ARP Table (IP -> MAC)
Map<String, String> arpTable = new HashMap<>();
arpTable.put("192.168.1.1", "AA:BB:CC:DD:EE:01");
arpTable.put("192.168.1.2", "AA:BB:CC:DD:EE:02");
arpTable.put("192.168.1.3", "AA:BB:CC:DD:EE:03");
// RARP Table (MAC -> IP)
Map<String, String> rarpTable = new HashMap<>();
rarpTable.put("AA:BB:CC:DD:EE:01", "192.168.1.1");
rarpTable.put("AA:BB:CC:DD:EE:02", "192.168.1.2");
rarpTable.put("AA:BB:CC:DD:EE:03", "192.168.1.3");
while (true) {
System.out.println("\n1. ARP (IP → MAC)");
System.out.println("2. RARP (MAC → IP)");
System.out.println("3. Exit");
System.out.print("Enter choice: ");
int choice = sc.nextInt();
sc.nextLine(); // consume newline
switch (choice) {
case 1:
System.out.print("Enter IP Address: ");
String ip = sc.nextLine();
if (arpTable.containsKey(ip)) {
System.out.println("MAC Address: " + arpTable.get(ip));
} else {
System.out.println("IP not found in ARP Table!");
}
break;
case 2:
System.out.print("Enter MAC Address: ");
String mac = sc.nextLine();
if (rarpTable.containsKey(mac)) {
System.out.println("IP Address: " + rarpTable.get(mac));
} else {
System.out.println("MAC not found in RARP Table!");
}
break;
case 3:
System.out.println("Exiting...");
return;
default:
System.out.println("Invalid choice!");
}
}
}
}