EX.
NO:
SIMULATION OF ARP PROTOCOL
DATE :
AIM:
To get the MAC or Physical address of the system using Address Resolution Protocol.
ALGORITHM:
SERVER:
1. Start the program
2. Create a datagram socket and bind it to client port.
3. Create a datagram packet to receive client message.
4. Wait for client's data and accept it.
5. Declare the array to store the IP Address and its equivalent MAC address. 6. Read Client's
IP Address using datagram receive method 7. Find the equivalent MAC address.
8. Create a datagram packet and send the MAC address to client.
9. Stop the program
CLIENT:
1. Start the program
2. Create a datagram socket and bind it to server port.
3. Get the IP address from user using BufferedReader.
4. Create a datagram packet and send the IP address to server’s ip address and client port.
5. Create a datagram packet to receive server’s message.
6. Read and display the MAC Address sent by the server.
7. Close the client socket.
8. Stop the program.
PROGRAM:
SERVER:
import java.io.*;
import java.net.*;
import java.util.*; class
Server {
public static void main(String args[]) { try
{
KGISL INSTITUTE OF TECHNOLOGY 711722104034
DatagramSocket server = new DatagramSocket(1309); while
(true) {
byte[] sendbyte = new byte[1024];
byte[] receivebyte = new byte[1024];
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[] = { "150.16.20.01", "172.16.9.17" };
String mac[] = { "6A:08:AA:C2", "8A:BC:E3:FA" };
System.out.println("server is running"); for (int i = 0;
i < ip.length; i++) { if (s.equals(ip[i])) { sendbyte =
mac[i].getBytes();
DatagramPacket sender = new DatagramPacket(sendbyte,
sendbyte.length, addr, port); server.send(sender); break; }
} break;
}
} catch (Exception e) {
System.out.println(e);
}
}
}
CLIENT:
import java.io.*; import
java.net.*; import
java.util.*; class Client
{
public static void main(String args[]) { try
{
KGISL INSTITUTE OF TECHNOLOGY 711722104034
DatagramSocket client = new DatagramSocket();
InetAddress addr = InetAddress.getByName("127.0.0.1");
byte[] sendbyte = new byte[1024]; byte[] receivebyte =
new byte[1024];
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Enter the logical address(IP):");
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 Physical Address is(MAC): " + s.trim()); client.close();
}
catch (Exception e) {
System.out.println(e);
}
}
}
OUTPUT:
KGISL INSTITUTE OF TECHNOLOGY 711722104034
RESULT:
Thus, the ARP protocol was implemented successfully to map IP addresses to their
corresponding physical addresses, with the output confirming accurate resolution.
KGISL INSTITUTE OF TECHNOLOGY 711722104034