0% found this document useful (0 votes)
21 views4 pages

ARP Protocol

program for ARP protocol

Uploaded by

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

ARP Protocol

program for ARP protocol

Uploaded by

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

Ex. No.

: 7A
SIMULATION OF ADDRESS RESOLUTION PROTOCOL (ARP)
Date :

AIM
To write a java program to implement ARP.

ABSTRACT:
ARP basically maps IP address with the MAC address or hardware address. For the
successful data transfer the software searches the corresponding MAC address of the destination in
the cache. If it founds, it returns the MAC address to sender but if it doesn't then it broadcast the
IP address on the LAN. The matching IP address machine replies directly to the sender. In this way
it works. For broadcasting, the software call functions or procedures (which act as machines in
the LAN) and sends ARP request in a particular format.

PROCEDURE: SERVER
1. Implementing necessary java package
2. Create a Server socket and bind it to port and accept the client connection.
3. Read the IP Address from the client request
4. Check it configuration file and compare with its logical address
5. If there is a match, send the host physical address.
6. Close the Server socket.

PROCEDURE: CLIENT
1. Import the necessary java packages.
2. Create a client socket and send the IP Address to server.
3. Receive the server response.
4. If it is MAC address, then display else display the message for “HOST NOT FOUND”.
5. Close the socket.

PROGRAM: SERVER
import java.io.*;
import java.net.*;
public class arpserver
{
public static void main(String args[])
{
String IP_Address[] = {"192.168.100.1","192.168.200.1","192.168.300.1",
"192.168.400.1","192.168.500.1"};
String MAC_Address[]={"57-H348-B2AQ01JY-6","93X-H64L-42AM-WHKY-4",
"IOV-JK48-2TAB-BEJY-8","89X-IOZ8-6ZLB-DHJY-3",
"XJH-4U18-3IAP-BPYS-7"};
String Send_msg,Recv_msg="";
try
{
ServerSocket ss=new ServerSocket(9124);
System.out.println("Server Started :\n"+ss);
Socket s=ss.accept();
DataInputStream dis=new DataInputStream(s.getInputStream());
DataInputStream d=new DataInputStream(System.in);
PrintStream ps=new PrintStream(s.getOutputStream());
Recv_msg=dis.readLine();
System.out.println("Request received is : "+Recv_msg);
int Host_found=0;
for(int i=0;i<5;i++)
if(IP_Address[i].equals(Recv_msg))
Host_found=i;
if(Host_found!=-1)
ps.println(MAC_Address[Host_found]);
else
ps.println(Host_found);
ps.close();
s.close();
}
catch(Exception se)
{
System.out.println("Server Socket Problem"+se.getMessage());
}
}
}

PROGRAM: CLIENT
import java.io.*;
import java.net.*;
class arpcli
{
public static void main(String args[])
{
String Send_msg,Recv_msg="";
try
{
InetAddress ip=InetAddress.getLocalHost();
Socket s=new Socket(ip,9124);
PrintStream ps=new PrintStream(s.getOutputStream());
DataInputStream dis=new DataInputStream(s.getInputStream());
DataInputStream d=new DataInputStream(System.in);
System.out.println("\n\t\t***Implementation of ARP***");
System.out.print("Enter the IP Address : ");
Send_msg=d.readLine();
ps.println(Send_msg);
Recv_msg=dis.readLine();
if(!Recv_msg.equals("-1"))
{
System.out.print("MAC Address of given IP Address : ");
System.out.println(Recv_msg);
}
else
System.out.println("HOST NOT FOUND");
ps.close();
s.close();
}
catch(Exception se)
{
System.out.println("Exception"+se.getMessage());
}
}
}
OUTPUT:

RESULT:
Thus, the java program to implement ARP was executed and the output was get the Mac
address for corresponding system excecuted successfully.

You might also like