-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleARP.java
More file actions
38 lines (30 loc) · 1.29 KB
/
SimpleARP.java
File metadata and controls
38 lines (30 loc) · 1.29 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 SimpleARP {
public static void main(String[] args) {
HashMap<String, String> arpTable = new HashMap<>();
Scanner sc = new Scanner(System.in);
// Pre-populate some entries
arpTable.put("192.168.1.1", "AA:BB:CC:DD:EE:01");
arpTable.put("192.168.1.2", "AA:BB:CC:DD:EE:02");
System.out.println("ARP PROTOCOL DEMO");
System.out.println("==================");
System.out.print("Enter IP address to resolve: ");
String ip = sc.nextLine();
// ARP Resolution
System.out.println("\nARP Request: Who has " + ip + "?");
if (arpTable.containsKey(ip)) {
String mac = arpTable.get(ip);
System.out.println("ARP Reply: " + ip + " is at " + mac);
System.out.println("\nData can be sent to MAC: " + mac);
} else {
System.out.println("No ARP reply received - Host unreachable!");
}
// Display ARP Table
System.out.println("\nCurrent ARP Table:");
System.out.println("IP\t\t\tMAC");
for (Map.Entry<String, String> e : arpTable.entrySet()) {
System.out.println(e.getKey() + "\t\t" + e.getValue());
}
sc.close();
}
}