-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleRARP.java
More file actions
38 lines (30 loc) · 1.32 KB
/
SimpleRARP.java
File metadata and controls
38 lines (30 loc) · 1.32 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
import java.util.*;
public class SimpleRARP {
public static void main(String[] args) {
HashMap<String, String> rarpTable = new HashMap<>();
Scanner sc = new Scanner(System.in);
// RARP Server entries (MAC -> IP)
rarpTable.put("AA:BB:CC:DD:EE:01", "192.168.1.10");
rarpTable.put("AA:BB:CC:DD:EE:02", "192.168.1.20");
System.out.println("RARP PROTOCOL DEMO");
System.out.println("===================");
System.out.print("Enter your MAC address: ");
String mac = sc.nextLine();
// RARP Resolution
System.out.println("\nRARP Request: What is my IP? My MAC is " + mac);
if (rarpTable.containsKey(mac)) {
String ip = rarpTable.get(mac);
System.out.println("RARP Reply: Your IP address is " + ip);
System.out.println("\nDevice configured with IP: " + ip);
} else {
System.out.println("No RARP reply - Cannot assign IP!");
}
// Display RARP Server Table
System.out.println("\nRARP Server Table:");
System.out.println("MAC\t\t\tIP");
for (Map.Entry<String, String> e : rarpTable.entrySet()) {
System.out.println(e.getKey() + "\t" + e.getValue());
}
sc.close();
}
}