-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRARPClient.java
More file actions
28 lines (23 loc) · 1005 Bytes
/
RARPClient.java
File metadata and controls
28 lines (23 loc) · 1005 Bytes
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
import java.net.*;
import java.util.Scanner;
public class RARPClient {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
InetAddress serverAddr = InetAddress.getByName("localhost");
int serverPort = 9092;
Scanner sc = new Scanner(System.in);
System.out.print("Enter MAC to resolve (e.g., 00:11:22:33:44:55): ");
String mac = sc.nextLine();
// Send RARP request as "REQUEST:<MAC>"
byte[] request = ("REQUEST:" + mac).getBytes();
ds.send(new DatagramPacket(request, request.length, serverAddr, serverPort));
System.out.println("Sent RARP Request for " + mac);
// Receive reply
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
ds.receive(dp);
String reply = new String(dp.getData(), 0, dp.getLength());
System.out.println("Received RARP Reply: " + reply);
ds.close();
}
}