Você está na página 1de 31

EX.

NO: IMPLEMENTATION OF ADDRESS RESOLUTION PROTOCOL


DATE :

AIM:

To implement Address Resolution Protocol .

ALGORITHM:

Client Side:

1. Establish a connection between the Client and Server.


Socket ss=new Socket(InetAddress.getLocalHost(),1100);
2. Create instance output stream writer .
PrintWriter ps=new PrintWriter(s.getOutputStream(),true);
3. Get the IP Address to resolve its physical address.
4. Send the IPAddress to its output Stream.
ps.println(ip);
5. Print the Physical Address received from the server.

Server Side:

1. Accept the connection request by the client.


ServerSocket ss=new ServerSocket(2000);
Socket s=ss.accept();
2 . Get the IPaddress from its inputstream.
BufferedReader br1=new BufferedReader(new
InputStreamReader(s.getInputStream()));
ip=br1.readLine();
3. During runtime execute the process
Runtime r=Runtime.getRuntime();
Process p=r.exec("arp -a "+ip);
4. Send the Physical Address to the client.
PROGRAM:ARP CLIENT

import java.io.*;
import java.net.*;
class ArpClient
{
public static void main(String args[])throws IOException
{
try
{
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
PrintStream ps=new PrintStream(ss.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String ip;
System.out.println("Enter the IPADDRESS:");
ip=br.readLine();
ps.println(ip);
String str,data;
BufferedReader br2=new BufferedReader(new
InputStreamReader(ss.getInputStream()));
System.out.println("ARP From Server::");
do
{
str=br2.readLine();
System.out.println(str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}
}

ARP SERVER

import java.io.*;
import java.net.*;
class ArpServer
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br1=new BufferedReader(new
InputStreamReader(s.getInputStream()));
String ip;
ip=br1.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec("arp -a "+ip);

BufferedReader br2=new BufferedReader(new


InputStreamReader(p.getInputStream()));
String str;
while((str=br2.readLine())!=null)
{
ps.println(str);
}
}
catch(IOException e)
{
System.out.println("Error"+e);
}
} }
OUTPUT

C:\Networking Programs>java ArpServer

C:\Networking Programs>java ArpClient


Enter the IPADDRESS:
192.168.11.58
ARP From Server::

Interface: 192.168.11.57 on Interface 0x1000003


Internet Address Physical Address Type
192.168.11.58 00-14-85-67-11-84 dynamic

RESULT:

Thus the implementation of ARP is done & executed


successfully.
IMPLEMENTATION OF ECHO

Echo Server
import java.io.*;
import java.net.*;
class EchoServer
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String str,data;
do
{ System.out.println("Server To LocalHost:");
str=br.readLine();
ps.println(str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}
Echo Client
import java.io.*;
import java.net.*;
class EchoClient
{
public static void main(String args[])throws IOException
{
try
{
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
BufferedReader br=new BufferedReader(new
InputStreamReader(ss.getInputStream()));
String str,data;
do
{
str=br.readLine();
System.out.println("Echo From Server::"+str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}

OUTPUT

SERVER WINDOW:
C:\Networking Programs>java EchoServer
Server To LocalHost:
hai
Server To LocalHost:
welcome
Server To LocalHost:
how are you
Server To LocalHost:
End

CLIENT WINDOW:
C:\Networking Programs>java EchoClient
Echo From Server::hai
Echo From Server::welcome
Echo From Server::how are you
Echo From Server::end
EX.NO: IMPLEMENTATION OF REMOTE METHOD INVOCATION
DATE :

AIM:

To implement remote method invocation.

ALGORITHM:

1.Create the rmi interface where the following methods are declared.

public int add(float a,float b)throws RemoteException;


public int multiply(int a,int b)throws RemoteException;
public float divide(float a,float b)throws RemoteException;

2.Implement remote objects at server side which are declared in the rmi
interface.

3. At client side the remote objects are called and their process is
executed.
PROGRAM:

RMI INTERFACE
import java.rmi.*;
public interface rmiInterface extends Remote
{
public int add(float a,float b)throws RemoteException;
public int multiply(int a,int b)throws RemoteException;
public float divide(float a,float b)throws RemoteException;
}

RMI SERVER
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
public class rmiServer extends UnicastRemoteObject implements
rmiInterface
{
public rmiServer()throws RemoteException
{}
public int add(float a,float b)throws RemoteException
{
int c;
c=(int)(a+b);
return(c);
}
public int multiply(int a,int b)throws RemoteException
{
int c;
c=(int)a*b;
return(c);
}
public float divide(float a,float b)throws RemoteException
{ float c;
c=(float)a/b;
return(c);
}
public static void main(String args[])throws Exception
{
try
{ rmiServer rs=new rmiServer();
Naming.rebind(args[0],rs);
}
catch(Exception e)
{ System.out.println("Error"+e);
}}}

RMI CLIENT

import java.io.*;
import java.rmi.*;
public class rmiClient
{
public static void main(String sdfs[])throws Exception
{
try
{
float a,b,c,d;
int e,f;
String rr;
rmiInterface ri=(rmiInterface)Naming.lookup(sdfs[0]);
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
do
{

System.out.println("1.Add()\n2.Multiply()\n3.Divide()\n4.Exit()\nEnter
U'R choice:");
int sw=Integer.parseInt(br.readLine());
switch(sw)
{
case 1:
System.out.println("Enter the First Value");
a=Float.parseFloat(br.readLine());
System.out.println("Enter the Second Value");
b=Float.parseFloat(br.readLine());
System.out.println("The Added Value Is:"+
ri.add(a,b));
break;
case 2:
System.out.println("Enter the First Value");
e=Integer.parseInt(br.readLine());
System.out.println("Enter the Second Value");
f=Integer.parseInt(br.readLine());
System.out.println("The Added Value Is:"+
ri.multiply(e,f));
break;
case 3:
System.out.println("Enter the First Value");
c=Float.parseFloat(br.readLine());
System.out.println("Enter the Second Value");
d=Float.parseFloat(br.readLine());
System.out.println("The Added Value Is:"+
ri.divide(c,d));
break;
case 4:
System.exit(0);
break;
}
System.out.println("Do u Want to Continue 1/0");
rr=br.readLine();
}while(rr.equalsIgnoreCase("1"));

}
catch(Exception e)
{
System.out.println("Error"+e);
}}}
OUTPUT

C:\Networking Programs>rmic rmiServer

C:\Networking Programs>start rmiregistry

C:\Networking Programs>java rmiServer 127.0.0.1

C:\Networking Programs>java rmiClient 127.0.0.1


1.Add()
2.Multiply()
3.Divide()
4.Exit()
Enter U'R choice:
1
Enter the First Value
12
Enter the Second Value
12
The Added Value Is:24
Do u Want to Continue 1/0
1
1.Add()
2.Multiply()
3.Divide()
4.Exit()
Enter U'R choice:
2
Enter the First Value
12
Enter the Second Value
12
The Added Value Is:144
Do u Want to Continue 1/0
0

RESULT:
Thus the implementation of RMI is done & executed
successfully.

IMPLEMENTATION OF REMOTE COMMAND EXECUTION

CLIENT PROGRAM:

import java.io.*;
import java.net.*;
class clientRCE
{
public static void main(String args[]) throws IOException
{ try {
String str;
Socket client=new Socket("127.0.0.1",6555);
PrintStream ps=new PrintStream(client.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("\t\t\t\tCLIENT WINDOW\n\n\t\tEnter The
Command:");
str=br.readLine();
ps.println(str);
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}}
SERVER PROGRAM:

import java.io.*;
import java.net.*;
class serverRCE
{
public static void main(String args[]) throws IOException
{
try
{ String str;
ServerSocket server=new ServerSocket(6555);
Socket s=server.accept();
BufferedReader br=new BufferedReader(new
InputStreamReader(s.getInputStream()));
str=br.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec(str);
}
catch(IOException e)
{
System.out.println("Error"+e);
}}}

OUTPUT
C:\Networking Programs>java serverRCE

C:\Networking Programs>java clientRCE


CLIENT WINDOW

Enter The Command:


Notepad
EX.NO: IMPLEMENTATION OF PING
DATE :

AIM:
To ping the server with its ipaddress.

ALGORITHM:
CLIENT SIDE:
1. Establish a connection between the Client and Server.
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
2. Create instances for input and output streams .
PrintStream ps=new PrintStream(ss.getOutputStream());
BufferedReader ips=new BufferedReader
(newInputStreamReader (ss.getInputStream()));
3. Get the ip address that is to be pinged.
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
ip=br.readLine();
4. Send the message to its output Stream.
ps.println(str);
SERVER SIDE:
1.Accept the connection request by the client.
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
2. Get the ip address sent by the client.
str=ips.readLine();
3. Print the pinging information.
Process p=r.exec("ping "+ip);
PROGRAM:

CLIENT PROGRAM:
import java.io.*;
import java.net.*;
class PingClient
{
public static void main(String args[])throws IOException
{
try
{
Socket ss=new Socket(InetAddress.getLocalHost(),1100);
PrintStream ps=new PrintStream(ss.getOutputStream());
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
String ip;
System.out.println("Enter the IPADDRESS:");
ip=br.readLine();
ps.println(ip);
String str,data;
BufferedReader br2=new BufferedReader(new
InputStreamReader(ss.getInputStream()));
System.out.println("Ping From Server::");
do
{
str=br2.readLine();
System.out.println(str);
}while(!(str.equalsIgnoreCase("end")));
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}

SERVER PROGRAM:
import java.io.*;
import java.net.*;
class PingServer
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket ss=new ServerSocket(1100);
Socket s=ss.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
BufferedReader br1=new BufferedReader(new
InputStreamReader(s.getInputStream()));
String ip;
ip=br1.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec("ping "+ip);
BufferedReader br2=new BufferedReader(new
InputStreamReader(p.getInputStream()));
String str;
while((str=br2.readLine())!=null)
{
ps.println(str);
}
}
catch(IOException e)
{
System.out.println("Error"+e);
} }}
OUTPUT
C:\Networking Programs>java PingServer
C:\Networking Programs>java PingClient
Enter the IPADDRESS:
192.168.11.57
Ping From Server::
Pinging 192.168.11.57 with 32 bytes of data:

Reply from 192.168.11.57: bytes=32 time<10ms TTL=128


Reply from 192.168.11.57: bytes=32 time<10ms TTL=128
Reply from 192.168.11.57: bytes=32 time<10ms TTL=128
Reply from 192.168.11.57: bytes=32 time<10ms TTL=128
Ping statistics for 192.168.11.57:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

RESULT:

Thus the implementation of PING is done & executed


successfully.
EX.NO: IMPLEMENTATION OF TALK
DATE :

AIM:
To implement TALK using User Datagram Protocol.

ALGORITHM:

SERVER SIDE:
1.Create datagram socket for theclient.
public static DatagramSocket ds;

2. Get the message to transfer.


BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
Str=br.readLine();

3. Send the datagram to its client .


ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));

4. Get the datagram sent by server

5.Thus the chatting between client and server is done until server
sends end signal
CLIENT SIDE:
1. Create datagram socket for theclient.
public static DatagramSocket ds;
2. Client receives the datagram sent by the server.
DatagramPacket p=new DatagramPacket(buffer, buffer.length);
ds.receive(p);
3. Client sends the reply to server;
4. Thus the chatting between client and server is done until client
sends end signal
PROGRAM:

CLIENT PROGRAM:

import java.io.*;
import java.net.*;
class SWPClient
{
public static void main(String args[])throws IOException
{
try
{
int client=3000,server=3002;
DatagramSocket ds=new DatagramSocket(client);
DatagramPacket dp;
byte outbuff[]=new byte[1024];
byte inbuff[]=new byte[1024];
String str,data;
DataInputStream dis=new DataInputStream(System.in);
do
{
System.out.println("To Server:");
str=dis.readLine();
outbuff=str.getBytes();
InetAddress ia=InetAddress.getLocalHost();
dp=new DatagramPacket(outbuff,str.length(),ia,server);
ds.send(dp);
System.out.println("From Server:");
dp=new DatagramPacket(inbuff,inbuff.length);
ds.receive(dp);
data=new String(dp.getData(),0,dp.getLength());
System.out.println(data);
}while(!(str.equalsIgnoreCase("end") ||
data.equalsIgnoreCase("end") ));
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}
}
SERVER PROGRAM:

import java.io.*;
import java.net.*;
class SWPServer
{
public static void main(String args[])throws IOException
{
try
{
int client=3000,server=3002;
DatagramSocket ds=new DatagramSocket(server);
DatagramPacket dp;
String str,data;
byte inbuff[]=new byte[1024];
byte outbuff[]=new byte[1024];
do
{
dp=new DatagramPacket(inbuff,inbuff.length);
ds.receive(dp);
str=new String(dp.getData(),0,dp.getLength());
System.out.println("From Client:"+str);
System.out.println("To Client:");
DataInputStream dis=new DataInputStream(System.in);
data=dis.readLine();
outbuff=data.getBytes();
InetAddress ia=dp.getAddress();
int port=dp.getPort();
dp=new DatagramPacket(outbuff,data.length(),ia,port);
ds.send(dp);
}while(!(str.equalsIgnoreCase("end") ||
data.equalsIgnoreCase("end") ));
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}
}
OUTPUT:

SERVER:

C:\Networking Programs>java SWPServer


From Client:from a
To Client:
from b
From Client:hai
To Client:
good day
From Client:ok
To Client:
End

CLIENT:

C:\Networking Programs>java SWPClient


To Server:
from a
From Server:
from b
To Server:
hai
From Server:
good day
To Server:
ok
From Server:
End

RESULT:
Thus the implementation of TALK is done & executed
successfully.

EX.NO: IMPLEMENTATION OF SHORTEST PATH ROUTING ALGORITHM


DATE:

AIM:

To implement shortest path routing algorithm to calculate shortest


path from source to destination.

ALGORITHM:

1.Read the number of nodes.


n=Integer.parseInt(n1);

2.Read the weight of each node


weight[i][j]=n3;

3.Read the source node


s=Integer.parseInt(s1);

4.Read the destination node


t=Integer.parseInt(t1)

5.Calculate the distance


If newdist<distance[i]
then distance[i]=newdist;
else
if distance[i]<smalldist
smalldist=distance[i];

6.Print the distance “ShortestPath="+pd;


PROGRAM:

import java.io.*;
class shortestPath
{
int n,infy,s,t,i,n1;
int weight[][]=new int[10][10];
int pd,k,dc;
int prem[]=new int[10];
int distance[]=new int[10];
int current,smalldist,newdist;
int j,n3;
shortestPath()
{
infy=1000;
}
void input()
{
try
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the no of nodes");
String n1=br.readLine();
n=Integer.parseInt(n1);
System.out.println("Enter the nodes");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
String n2=br.readLine();
n3=Integer.parseInt(n2);
weight[i][j]=n3;
}
}
System.out.println("Enter the source");
String s1=br.readLine();
s=Integer.parseInt(s1);
System.out.println("Enter the Destination");
String t1=br.readLine();
t=Integer.parseInt(t1);
}
catch(IOException e)
{
System.out.println("Error"+e);
}
spath(s,t);
}
void spath(int s,int t)
{
for(i=0;i<n;i++)
{
prem[i]=0;
distance[i]=infy;
}
distance[s]=0;
prem[s]=1;
current=s;
while(current!=t)
{
smalldist=infy;
dc=distance[current];
for(i=0;i<n;i++)
{
if(prem[i]==0)
{
newdist=dc+weight[current][i];
if(newdist<distance[i])
{
distance[i]=newdist;
}
if(distance[i]<smalldist)
{
smalldist=distance[i];
k=i;
}}}
current=k;
prem[current]=1;
}
pd=distance[t];
System.out.println("ShortestPath="+pd);
}
public static void main(String args[])throws IOException
{
shortestPath sp=new shortestPath();
sp.input();
}}
OUTPUT

C:\Networking Programs>java shortestPath

Enter the no of nodes


5

Enter the weight

1000
10
20
30
200

1000
1000
1000
50
1000

1000
1000
1000
1000
1000

1000
1000
1000
1000
60

1000
1000
70
1000
1000

Enter the source:0

Enter the Destination:4

ShortestPath=90
RESULT:

Thus the implementation of shortest path is done & executed


successfully.
EX.NO:IMPLEMENTATION OF REVERSE ADDRESS RESOLUTION PROTOCOL
DATE :

AIM:

To implement Reverse Address Resolution Protocol .

ALGORITHM:

Client Side:

1. Establish a connection between the Client and Server.


Socket ss=new Socket(InetAddress.getLocalHost(),1100);
2. Create instance output stream writer .
PrintWriter ps=new PrintWriter(s.getOutputStream(),true);
3. Get the Physical Address to resolve its IP address.
4. Send the Physical Address to its output Stream.
5. Print the IP address received from the server.

Server Side:

1. Accept the connection request by the client.


ServerSocket ss=new ServerSocket(2000);
Socket s=ss.accept();
2 . Get the Physical address from its inputstream.
3. During runtime execute the process
Runtime r=Runtime.getRuntime();
Process p=r.exec("arp -a "+ip);
4. Send the Physical Address to the client.
PROGRAM:

RARP CLIENT:
import java.io.*;
import java.net.*;
class rarpclient
{
public static void main(String args[])throws IOException
{
Socket s1=new Socket("localhost",3500);
DataInputStream in=new DataInputStream(s1.getInputStream());
DataOutputStream on=new DataOutputStream(s1.getOutputStream());
BufferedReader b=new BufferedReader(new
InputStreamReader(System.in));
while(true)
{
System.out.println("Enter mac add");
String o=b.readLine() ;
on.writeUTF(o);
String t=in.readUTF();
System.out.println("The IP add"+t);
}
}
}
RARP SERVER:
import java.io.*;
import java.net.*;
class rarpserver
{
public static void main(String args[])throws IOException
{
ServerSocket s=new ServerSocket(3500);
Socket c=s.accept();
DataInputStream i=new DataInputStream(c.getInputStream());
DataOutputStream o=new DataOutputStream(c.getOutputStream());
BufferedReader b=new BufferedReader(new
InputStreamReader(System.in));
String ip[]=new String[100];
String mac[]=new String[100];
System.out.println("How many add to be updated");
int n=Integer.parseInt(b.readLine());
int f=0,h=0;
for(int j=0;j<n;j++)
{
int u=j+1;
System.out.println("Enter the "+u+"ip address");
ip[j]=b.readLine();
System.out.println("Enter CORRES mac address");
mac[j]=b.readLine();
}
while(true)
{
f=0;
String t=i.readUTF();
System.out.println("Please send the ip add of"+t);
for(int k=0;k<n;k++)
{
if(mac[k].equals(t))
{
o.writeUTF(ip[k]);
f=1;
break;
}
}
if(f==0)
{o.writeUTF("add cannot be resolved");
}
}
}
}
OUTPUT:

C:\jdk1.3\bin>javac rarpserver.java

C:\jdk1.3\bin>java rarpserver
How many add to be updated
2
Enter the 1ip address
192.168.0.10
Enter CORRES mac address
10
Enter the 2ip address
192.168.0.23
Enter CORRES mac address
23
Please send the ip add of10
Please send the ip add of23
Please send the ip add of12

C:\jdk1.3\bin>javac rarpclient.java

C:\jdk1.3\bin>java rarpclient
Enter mac add
10
The IP add192.168.0.10
Enter mac add
23
The IP add192.168.0.23
Enter mac add
12
The IP addadd cannot be resolved

RESULT:

Thus the implementation RARP is done & executed


successfully.

Você também pode gostar