Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 47

Panipat Institute of Engineering & Technology,

Samalkha, (Haryana)
Computer Science & Engineering Department

Computer Network
Lab
PC-CS- 308LA
Submitted to: Submitted by:
Mr. Kunar Uppal DHIRAJ KUMAR
(Assistant Prof.) ROLL NO. 2820243
CSE Department B.tech CSE 6th SEM

A
ff
il
ia
te
d
t
o

Kurukshetra University Kurukshetra, India


INDEX

S.No. Practical Date Signature

1. To create a LAN connection between


switches, Communication of devices
between switches.
2. To Perform Basic Router Security
Configuration-1.

3. To Perform Basic Router Security


Configuration-2.

4. To Perform Basic Router Security


Configuration – 3.

5. To write a java program for simulating


ARP protocols using TCP
6. To write a java program for simulating
RARP protocols using UDP

7. To implement a Simple Calculator using


TCP in Java.

8. To simulate a sliding window protocol that


uses Go Back N ARQ.
PRACTICAL-1

Aim-To create a LAN connection between switches, Communication of


devices between switches.

STEP 1: Firstly, we have to take two routers and then connect with each other
by using connection wire and then take no. of pc’s and connect them to the
switches separately as shown below.
STEP2:Now click on switch0 and switch 1 open CLI(Command Line Interface)

and then do below commands -


Now, do same commands with switch 1-
STEP 3: Now give Ip addresses to all connected PC.

We can give IP Addresses to the PC by clicking on any PC and then open IP


configuration in the desktop section and do some steps which are shown below -

In the above Picture we have given 192.168.1.1 in the IP address and then we
click on Subnet Mask it will automatically fill its value with 255.255.255.0.

Now same process will be done for remaining PC for giving them IP Addresses.

STEP 4: Now try to transfer packets from one pc to another through switches.
The above picture shows the information of packet which is being transfers.
STEP 5: Hence by doing above steps we create a communication connection
between switches.
PRACTICAL-2-

AIM-Perform Basic Router Security Configuration-1.

STEP1- Connect Router 2 and Router 3 by their GigabitEthernet0/0 interfaces.

STEP2-Set the hostnames according to the network diagram (R1 and R2) by
using CLI and Set the enable password on each router to 'cisco.

Now, View the password in the running configuration(do sh run). Is it


encrypted?
STEP 3-Enable password encryption on each router.

Now, View again the password in the running configuration. Is it encrypted?


STEP 4-At last Now, type copy running config-start command.

 Same steps will be done for Router 3.


PRACTICAL-3-

AIM-Perform Basic Router Security Configuration-2.

STEP 1-Connect the two routers by their GigabitEthernet0/0 interfaces.

STEP 2-Set the hostname of each router according to the network diagram (R1
and R2) and Set the enable password of each router to 'cisco'.
Now, Set the enable secret of each router to 'ccna'

STEP 3-Exit back (by using exit command) to exec mode and try to enter
privileged exec mode. Which password do you have to use?

Here we have to use Cisco password for enabling privileged-exec mode.


Now, View the running configuration. Which of the passwords is encrypted?

STEP 4- Enable password encryption on the router and view the running
configuration. What has changed?
STEP 5- Save the configuration and reload the router to confirm.

 Same steps will be done for Router 3.


PRACTICAL- 4-

AIM- Perform Basic Router Security Configuration – 3.

STEP 1-Connect PC0's RS-232 port to Router 0's console port.

STEP 2- Use the console connection to configure the router from PC1. Change
the hostname to R1.

 Set the enable secret of R1 to 'cisco.


 Set the console password of R1 to 'ccna', and make it required to connect
to R1 by the console port.
STEP 3- Exit back (by using exit command) to exec mode and try to enter
privileged exec mode. Which password do you have to use?

In the above Picture firstly, we have to use console password ccna and then if
we want to enter into the privileged-exec mode we have to input password
cisco.
STEP 4- Enable password encryption on R1 Verify by checking the running
configuration, and then save your configurations.
Now, Save your configurations.
PRACTICAL- 5

Aim: To write a java program for simulating ARP protocols using TCP

ALGORITHM:

Client

1. Start the program

2. Using socket connection is established between client and server.

3. Get the IP address to be converted into MAC address.

4. Send this IP address to server. 5. Server returns the MAC address to client.

Server

1. Start the program

2. Accept the socket which is created by the client.

3. Server maintains the table in which IP and corresponding MAC addresses are stored.

4. Read the IP address which is send by the client.

5. Map the IP address with its MAC address and return the MAC address to client.

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",5604);

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(5604);

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);

}
PRACTICAL-6
Aim: To write a java program for simulating RARP protocols using UDP

ALGORITHM

Client

1.Start the program 2. using datagram sockets UDP function is established.

2.Get the MAC address to be converted into IP address.

3.Send this MAC address to server.

4.Server returns the IP address to client.

Server

1. Start the program.

2. Server maintains the table in which IP and corresponding MAC addresses are stored.

3. Read the MAC address which is send by the client.

4. Map the IP address with its MAC address and return the IP address to client.

Program

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

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();

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(e);

}
Output
Practical-7
Aim: To implement a Simple Calculator using TCP in Java.

Client Side Implementation

// Java program to illustrate Client Side Programming

// for Simple Calculator using TCP

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.IOException;

import java.net.InetAddress;

import java.net.Socket;

import java.net.UnknownHostException;

import java.util.Scanner;

public class Calc_Client

public static void main(String[] args) throws IOException

InetAddress ip = InetAddress.getLocalHost();

int port = 4444;

Scanner sc = new Scanner(System.in);

// Step 1: Open the socket connection.

Socket s = new Socket(ip, port);

// Step 2: Communication-get the input and output stream


DataInputStream dis = new DataInputStream(s.getInputStream());

DataOutputStream dos = new


DataOutputStream(s.getOutputStream());

while (true)

// Enter the equation in the form-

// "operand1 operation operand2"

System.out.print("Enter the equation in the form: ");

System.out.println("'operand operator operand'");

String inp = sc.nextLine();

if (inp.equals("bye"))

break;

// send the equation to server

dos.writeUTF(inp);

// wait till request is processed and sent back to client

String ans = dis.readUTF();

System.out.println("Answer=" + ans);

}
Output

Enter the equation in the form: 'operand operator operand'

5*6

Answer=30

Enter the equation in the form: 'operand operator operand'

5+6

Answer=11

Enter the equation in the form: 'operand operator operand'

9/3

Answer=3

Server-Side Programming

// Java program to illustrate Server Side Programming

// for Simple Calculator using TCP

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.IOException;

import java.net.ServerSocket;

import java.net.Socket;

import java.util.StringTokenizer;

public class Calc_Server

public static void main(String args[]) throws IOException

{
// Step 1: Establish the socket connection.

ServerSocket ss = new ServerSocket(4444);

Socket s = ss.accept();

// Step 2: Processing the request.

DataInputStream dis = new DataInputStream(s.getInputStream());

DataOutputStream dos = new


DataOutputStream(s.getOutputStream());

while (true)

// wait for input

String input = dis.readUTF();

if(input.equals("bye"))

break;

System.out.println("Equation received:-" + input);

int result;

// Use StringTokenizer to break the equation into operand and

// operation

StringTokenizer st = new StringTokenizer(input);


int oprnd1 = Integer.parseInt(st.nextToken());

String operation = st.nextToken();

int oprnd2 = Integer.parseInt(st.nextToken());

// perform the required operation.

if (operation.equals("+"))

result = oprnd1 + oprnd2;

else if (operation.equals("-"))

result = oprnd1 - oprnd2;

else if (operation.equals("*"))

result = oprnd1 * oprnd2;

else

result = oprnd1 / oprnd2;

System.out.println("Sending the result...");

// send the result back to the client.


dos.writeUTF(Integer.toString(result));

Output:

Equation received:-5 * 6

Sending the result...

Equation received:-5 + 6

Sending the result...

Equation received:-9 / 3

Sending the result...

Practical-8
Aim: To simulate a sliding window protocol that uses Go Back N ARQ.

/*Server Program*/

import java.net.*;

import java.io.*;

import java.util.*;

public class Server

public static void main(String args[]) throws Exception

ServerSocket server=new ServerSocket(6262);

System.out.println(“Server established.”);

Socket client=server.accept();

ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());

ObjectInputStream ois=new ObjectInputStream(client.getInputStream());

System.out.println(“Client is now connected.”);

int x=(Integer)ois.readObject();

int k=(Integer)ois.readObject();

int j=0;

int i=(Integer)ois.readObject();

boolean flag=true;

Random r=new Random(6);

int mod=r.nextInt(6);

while(mod==1||mod==0)

mod=r.nextInt(6);
while(true)

int c=k;

for(int h=0;h<=x;h++)

System.out.print(“|”+c+”|”);

c=(c+1)%x;

System.out.println();

System.out.println();

if(k==j)

System.out.println(“Frame “+k+” recieved”+”\n”+”Data:”+j);

j++;

System.out.println();

else

System.out.println(“Frames recieved not in correct order”+”\n”+” Expected farme:” +


j +”\n”+ ” Recieved frame no :”+ k);

System.out.println();

if(j%mod==0 && flag)

System.out.println(“Error found. Acknowledgement not sent. “);

flag=!flag;

j–;
}

else if(k==j-1)

oos.writeObject(k);

System.out.println(“Acknowledgement sent”);

System.out.println();

if(j%mod==0)

flag=!flag;

k=(Integer)ois.readObject();

if(k==-1)

break;

i=(Integer)ois.readObject();

System.out.println(“Client finished sending data. Exiting”);

oos.writeObject(-1);

/*Client Program*/

import java.util.*;

import java.net.*;

import java.io.*;

public class Client

public static void main(String args[]) throws Exception


{

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

System.out.print(“Enter the value of m : “);

int m=Integer.parseInt(br.readLine());

int x=(int)((Math.pow(2,m))-1);

System.out.print(“Enter no. of frames to be sent:”);

int count=Integer.parseInt(br.readLine());

int data[]=new int[count];

int h=0;

for(int i=0;i<count;i++)

System.out.print(“Enter data for frame no ” +h+ ” => “);

data[i]=Integer.parseInt(br.readLine());

h=(h+1)%x;

Socket client=new Socket(“localhost”,6262);

ObjectInputStream ois=new ObjectInputStream(client.getInputStream());

ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());

System.out.println(“Connected with server.”);

boolean flag=false;

GoBackNListener listener=new GoBackNListener(ois,x);

listener=new GoBackNListener(ois,x);

listener.t.start();

int strt=0;

h=0;
oos.writeObject(x);

do

int c=h;

for(int i=h;i<count;i++)

System.out.print(“|”+c+”|”);

c=(c+1)%x;

System.out.println();

System.out.println();

h=strt;

for(int i=strt;i<x;i++)

System.out.println(“Sending frame:”+h);

h=(h+1)%x;

System.out.println();

oos.writeObject(i);

oos.writeObject(data[i]);

Thread.sleep(100);

listener.t.join(3500);

if(listener.reply!=x-1)

{
System.out.println(“No reply from server in 3.5 seconds. Resending data from frame
no ” + (listener.reply+1));

System.out.println();

strt=listener.reply+1;

flag=false;

else

System.out.println(“All elements sent successfully. Exiting”);

flag=true;

}while(!flag);

oos.writeObject(-1);

class GoBackNListener implements Runnable

Thread t;

ObjectInputStream ois;

int reply,x;

GoBackNListener(ObjectInputStream o,int i)

t=new Thread(this);

ois=o;

reply=-2;
x=i;

@Override

public void run() {

try

int temp=0;

while(reply!=-1)

reply=(Integer)ois.readObject();

if(reply!=-1 && reply!=temp+1)

reply=temp;

if(reply!=-1)

temp=reply;

System.out.println(“Acknowledgement of frame no ” + (reply%x) + ” recieved.”);

System.out.println();

reply=temp;

catch(Exception e)

System.out.println(“Exception => ” + e);

}
}

/*Client Output

Enter the value of m : 7

Enter no. of frames to be sent:5

Enter data for frame no 0 => 1

Enter data for frame no 1 => 2

Enter data for frame no 2 => 3

Enter data for frame no 3 => 4

Enter data for frame no 4 => 5

Connected with server.

|0||1||2||3||4|

Sending frame:0

Acknowledgement of frame no 0 recieved.

Sending frame:1

Sending frame:2

Sending frame:3

Sending frame:4
Sending frame:5

*/

/*Server Output

Server established.

Client is now connected.

|0||1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||
20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||
37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||
54||55||56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||
71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||
88||89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||
104||105||106||107||108||109||110||111||112||113||114||115||116||117||
118||119||120||121||122||123||124||125||126||0|

Frame 0 recieved

Data:0

Acknowledgement sent

|1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||
21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||
38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||
55||56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||
72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||
89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||
105||106||107||108||109||110||111||112||113||114||115||116||117||118||
119||120||121||122||123||124||125||126||0||1|

Frame 1 recieved
Data:1

Error found. Acknowledgement not sent.

|2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||
21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||
38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||
55||56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||
72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||
89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||
105||106||107||108||109||110||111||112||113||114||115||116||117||118||
119||120||121||122||123||124||125||126||0||1||2|

Frames recieved not in correct order

Expected farme:1

Recieved frame no :2

|3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||
22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||38||
39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||
56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||72||
73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||
90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||
106||107||108||109||110||111||112||113||114||115||116||117||118||119||
120||121||122||123||124||125||126||0||1||2||3|

Frames recieved not in correct order

Expected farme:1

Recieved frame no :3

|4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||
23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||38||39||
40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||
57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||72||73||
74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||
91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||
107||108||109||110||111||112||113||114||115||116||117||118||119||120||
121||122||123||124||125||126||0||1||2||3||4|

Frames recieved not in correct order

Expected farme:1

Recieved frame no :4

*/

You might also like