0% found this document useful (0 votes)
31 views2 pages

Import Import Import Public Class Public Static Void Try New Byte New Byte Byte New Byte in New New in Out in New

This Java code defines a RARP (Reverse Address Resolution Protocol) client and server. The client takes in a physical address from the user, sends it to the server, and prints the returned logical address. The server listens for physical addresses, matches them to its hardcoded list of IP/MAC pairs, and sends back the corresponding IP address.

Uploaded by

Bavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Import Import Import Public Class Public Static Void Try New Byte New Byte Byte New Byte in New New in Out in New

This Java code defines a RARP (Reverse Address Resolution Protocol) client and server. The client takes in a physical address from the user, sends it to the server, and prints the returned logical address. The server listens for physical addresses, matches them to its hardcoded list of IP/MAC pairs, and sends back the corresponding IP address.

Uploaded by

Bavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.io.

*;
import java.net.*;
import java.util.*;

public class RARP {


public static void main(String args[]){
try{
DatagramSocket client = new DatagramSocket();
InetAddress addr = InetAddress.getByName("127.0.0.1");
byte[] sendByte = new byte[1204];
byte[] receiveByte = new byte[1024];
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Physical Address ");
String str = in.readLine();
sendByte = str.getBytes();
DatagramPacket sender = new
DatagramPacket(sendByte,sendByte.length,addr,1309);
client.send(sender);
DatagramPacket receiver = new
DatagramPacket(receiveByte,receiveByte.length);
client.receive(receiver);
String s = new String(receiver.getData());
System.out.println("The Logical Address is :" + s.trim());
client.close();
}
catch(Exception e){
System.out.println(e);
}
}
}

import java.io.*;
import java.net.*;
import java.util.*;

public class RARPServer{

public static void main(String args[]) {


try{

DatagramSocket server = new DatagramSocket(1309);


while(true){
byte[] sendByte = new byte[1204];
byte[] receiveByte = new byte[1204];
DatagramPacket receiver = new
DatagramPacket(receiveByte,receiveByte.length);
server.receive(receiver);
String str = new String(receiver.getData());
String s = str.trim();
InetAddress addr = receiver.getAddress();
int port = receiver.getPort();
String ip[] = {"10.0.3.186"};
String mac[] = {"D4:3D:7E:12:A3:D9"};

for (int i = 0; i < ip.length; i++) {


if(s.equals(mac[i]))
{
sendByte = ip[i].getBytes();
DatagramPacket sender = new
DatagramPacket(sendByte,sendByte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}catch(Exception e)
{
System.out.println(e);
}
}
}

You might also like