Skip to content

Commit 9935650

Browse files
Add files via upload
This is the program for Implementation of Reverse Address Resolution Protocol (RARP).
1 parent cdd4496 commit 9935650

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

RARPClient.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.io.*;
2+
import java.net.*;
3+
public class RARPClient
4+
{
5+
public static void main(String args[])
6+
{
7+
String send_msg, recv_msg=" ";
8+
try
9+
{
10+
InetAddress ip=InetAddress.getLocalHost();
11+
Socket s=new Socket(ip, 9126);
12+
PrintStream ps=new PrintStream(s.getOutputStream());
13+
DataInputStream dis=new DataInputStream(s.getInputStream());
14+
DataInputStream d=new DataInputStream(System.in);
15+
System.out.println("\n\t\t***Implementation of RARP***\n");
16+
System.out.println("\nEnter the MAC Address: ");
17+
send_msg=d.readLine();
18+
ps.println(send_msg);
19+
recv_msg=dis.readLine();
20+
if (!recv_msg.equals("-1"))
21+
{
22+
System.out.println("\nIP Address of given MAC Address: ");
23+
System.out.println(recv_msg);
24+
}
25+
else
26+
{
27+
System.out.println("Host Not Found\n");
28+
}
29+
ps.close();
30+
s.close();
31+
}catch (Exception se) {System.out.println("Exception: "+se.getMessage());}
32+
}
33+
}

RARPServer.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.io.*;
2+
import java.net.*;
3+
public class RARPServer
4+
{
5+
public static void main(String args[])
6+
{
7+
String IP_Address[]={"192.168.100.1", "192.168.200.1", "192.168.300.1", "192.168.400.1", "192.168.500.1"};
8+
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"};
9+
String send_msg, recv_msg=" ";
10+
System.out.println("\n\t\t***Implementation of RARP***\n");
11+
try
12+
{
13+
ServerSocket ss=new ServerSocket(9126);
14+
System.out.println("\nServer started: "+ss);
15+
Socket s=ss.accept();
16+
DataInputStream dis=new DataInputStream(s.getInputStream());
17+
DataInputStream d=new DataInputStream(System.in);
18+
PrintStream ps=new PrintStream(s.getOutputStream());
19+
recv_msg=dis.readLine();
20+
System.out.println("\nRequest received is: "+recv_msg);
21+
int host_found=-1;
22+
for (int i=0; i<5; i++)
23+
{
24+
if (MAC_Address[i].equals(recv_msg))
25+
host_found=i;
26+
}
27+
if (host_found!=-1)
28+
ps.println(IP_Address[host_found]);
29+
else
30+
ps.println(host_found);
31+
ps.close();
32+
s.close();
33+
}catch (Exception se) {System.out.println("Server Socket Problem "+se.getMessage());}
34+
}
35+
}

0 commit comments

Comments
 (0)