0% found this document useful (0 votes)
229 views5 pages

Ex 3 ARP RARP

The document describes the simulation of ARP and RARP protocols using Java programs for the client and server. The ARP client program takes an IP address as input and returns the corresponding MAC address by communicating with the ARP server program. The RARP client program takes a MAC address as input and returns the corresponding IP address by communicating with the RARP server program. The client and server programs for both ARP and RARP are provided, along with sample outputs showing the address resolution processes.

Uploaded by

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

Ex 3 ARP RARP

The document describes the simulation of ARP and RARP protocols using Java programs for the client and server. The ARP client program takes an IP address as input and returns the corresponding MAC address by communicating with the ARP server program. The RARP client program takes a MAC address as input and returns the corresponding IP address by communicating with the RARP server program. The client and server programs for both ARP and RARP are provided, along with sample outputs showing the address resolution processes.

Uploaded by

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

PANIMALAR ENGINEERING COLLEGE

DEPARTMENT OF CSE
211416104185

SIMULATION OF ARP/RARP PROTOCOLS

ADDRESS RESOLUTION PROTOCOL (ARP)

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);
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF CSE
211416104185
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
System.out.println(“Processing….”)
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("Physical Address Retrieval Processing");
}
}
OUTPUT:

SERVER:
Z:\>java Serverarp
Physical Address Retrieval Processing

CLIENT:
Z:\>javac Clientarp.java
Note: Clientarp.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Z:\>java Clientarp
Enter the Logical address(IP):
165.165.80.80
The Physical Address is: 6A:08:AA:C2
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF CSE
211416104185

REVERSE ADDRESS RESOLUTUION PROTOCOL (RARP)

CLIENT:

import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
public static void main(String args[])
{
try
{
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 Physical address (MAC):");

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(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

SERVER:

import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp
{
public static void main(String args[])
{
try
{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF CSE
211416104185

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();
//System.out.println(s);
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
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(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("Logical Address Retrieval Processing");
}
}

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF CSE
211416104185

SERVER:
Z:\>java Serverrarp
Logical Address Retrieval Processing

CLIENT:
Z:\>javac Clientarp.java
Note: Clientrarp.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Z:\>java Clientrarp
Enter the Physical address (MAC): 6A:08:AA:C2

The Logical address is(IP):


165.165.80.80

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy