Ex Arp
Ex Arp
AIM:
To implement an ARP(Address Resolution Protocol) program to communicate between client
and server to convert IP to MAC .
PROCEDURE:
The address resolution protocol (arp) is a protocol used by the Internet Protocol (IP) [RFC826],
specifically IPv4, to map IP network addresses to the hardware addresses used by a data link
protocol. The protocol operates below the network layer as a part of the interface between the
OSI network and OSI link layer.
The important terms associated with ARP are :
1. ARP Cache: After resolving MAC address, the ARP sends it to the source where it stores
in a table for future reference. The subsequent communications can use the MAC address
from the table
2. ARP Cache Timeout: It indicates the time for which the MAC address in the ARP cache
can reside
3. ARP request: This is nothing but broadcasting a packet over the network to validate
whether we came across destination MAC address or not.
ARP request packet contains:
1. The physical address of the sender.
2. The IP address of the sender.
3. The physical address of the receiver is 0s.
4. The IP address of the receiver
Note, that the ARP packet is encapsulated directly into data link frame.
4. ARP response/reply: It is the MAC address response that the source receives from the
destination which aids in further communication of the data.
ALGORITHM:
Initialize the string of ip addresses
For every ip address, assign an ethernet address
: To Perform ARP, enter the ip address
: The equivalent ethernet address is displayedStep
: If the ethernet address is not found, then 'not found' message is displayeS
: To Perform RARP, enter the ethernet address
: The equivalent ip address is displayed
: If the ip address is not found, then 'not found' message is displayed
: Provide option to perform both ARP and RARP
:Choose Exit option to terminate the program
PROGRAM:
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
{
public static void main(String args[])
{
try {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the Logical address(IP):");
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
System.out.println("The Physical Address is: "+str);
clsct.close();
} catch (Exception e){
System.out.println(e);
}}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp
{
public static void main(String args[])
{try{
ServerSocket obj=new ServerSocket(139);
Socket obj1=obj.accept();
while(true){
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{if(str.equals(ip[i])){
dout.writeBytes(mac[i]+'\n');
break;
}}obj.close();
}}
catch(Exception e)
{System.out.println(e);
}}
}
OUTPUT:
E:\networks>java Serverarp
E:\networks>java Clientarp
Enter the Logical address(IP):
165.165.80.80
The Physical Address is: 6A:08:AA:C2
RESULT:
Thus the above ARP has been implemented and executed successfully.