You are on page 1of 134

CS506PC: COMPUTER NETWORKS AND WEB TECHNOLOGIES LAB

Course Objectives

1. To understand the working principle of various communication protocols.


2. To understand the network simulator environment and visualize a network topology and observe its
performance
3. To analyze the traffic flow and the contents of protocol frames

Course Outcomes
1. Implement data link layer farming methods
2. Analyze error detection and error correction codes.
3. Implement and analyze routing and congestion issues in network design.
4. Implement Encoding and Decoding techniques used in presentation layer
5. To be able to work with different network tools

List of Experiments

1. Implement the data link layer framing methods such as character, character-stuffing and bit
stuffing.

2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP

3. Develop a simple data link layer that performs the flow control using the sliding window protocol,
and loss recovery using the Go-Back-N mechanism.

4. Implement Dijsktra’s algorithm to compute the shortest path through a network

5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.

6. Implement distance vector routing algorithm for obtaining routing tables at each node.

7. Implement data encryption and data decryption

8. Write a program for congestion control using Leaky bucket algorithm.


9. Write a program for frame sorting technique used in buffers.

10. Wireshark
i. Packet Capture Using Wire shark ii. Starting
Wire shark iii. Viewing Captured Traffic iv.
Analysis and Statistics & Filters.
11. How to run Nmap scan

12. Operating System Detection using Nmap

13. Do the following using NS2 Simulator


i. NS2 Simulator-Introduction ii. Simulate to
Find the Number of Packets Dropped iii. Simulate to
Find the Number of Packets Dropped by TCP/UDP
iv. Simulate to Find the Number of Packets Dropped
due to Congestion v. Simulate to Compare Data
Rate& Throughput.
vi. Simulate to Plot Congestion for Different Source/Destination vii. Simulate to
Determine the Performance with respect to Transmission of Packets Web
Technologies Experiments

1. Write a PHP script to print prime numbers between 1-50.

2. PHP script to a. Find the length of a string. b. Count no of words in a string. c. Reverse a string. d.
Search for a specific string.

3. Write a PHP script to merge two arrays and sort them as numbers, in descending order.

4. Write a PHP script that reads data from one file and write into another file.

5. Develop static pages (using Only HTML) of an online book store. The pages should resemble:
www.amazon.com. The website should consist the following pages.

a) Home page
b) Registration and user Login
c) User Profile Page
d) Books catalog
e) Shopping Cart
f) Payment By credit card
g) Order Conformation

6. Validate the Registration, user login, user profile and payment by credit card pages using JavaScript.

7. Create and save an XML document on the server, which contains 10 users information. Write a
program, which takes User Id as an input and returns the user details by taking the user information
from the XML document.

8. Install TOMCAT web server. Convert the static web pages of assignments 2 into dynamic web pages
using servlets and cookies. Hint: Users information (user id, password, credit card number) would be
stored in web.xml. Each user should have a separate Shopping Cart.

9. Redo the previous task using JSP by converting the static web pages of assignments 2 into dynamic
web pages. Create a database with user information and books information. The books catalogue
should be dynamically loaded from the database. Follow the MVC architecture while doing the
website.

TEXT BOOKS: 1. WEB TECHNOLOGIES: A Computer Science Perspective, Jeffrey C. Jackson,


Pearson Education

REFERENCES:

1. Deitel H.M. and Deitel P.J., “Internet and World Wide Web How to program”, Pearson
International, 2012, 4th Edition.

2. J2EE: The complete Reference By James Keogh, McGraw-Hill

3. Bai and Ekedhi, The Web Warrior Guide to Web Programming, Thomson

4. Paul Dietel and Harvey Deitel,” Java How to Program”, Prentice Hall of India, 8th Edition

5. Web technologies, Black Book, Dreamtech press.

6. Gopalan N.P. and Akilandeswari J., “Web Technology”, Prentice Hall of India III Year B.Tech.
CSE I-Sem
COMPUTER NETWORKS LAB PROGRAMS
1. Implement the data link layer framing methods such as character, character-stuffing and bit
stuffing.

CHARACTER STUFFING PROGRAM

ALGORITHM:
Begin

Step 1: Initialize I and j as 0


Step 2: Declare n and pos as integer and a[20],b[50],ch as character
Step 3: read the string a
Step 4: find the length of the string n, i.e. n-strlen(a)
Step 5: read the position, pos
Step 6: if pos> n then
Step 7: print invalid position and read again the position, pos
Step 8: end if
Step 9: read the character, ch
Step 10: Initialize the array b , b[0…5] as ’d’, ’l’, ’e’, ’s’ ,’t’ ,’x’ respectively
Step 11: j=6;
Step 12: Repeat step[(13to22) until i<n
Step 13: if i==pos-1 then
Step 14: initialize b array, b[j],b[j+1]…b[j+6] as ‘d’, ‘l’, ‘e’ ,’ch, ’d’, ‘l’,‘e’ respectively
Step 15: increment j by 7, i.e j=j+7
Step 16: end if
Step 17: if a[i]==’d’ and a[i+1]==’l’ and a[i+2]==’e’ then
Step 18: initialize array b, b[13…15]=’d’, ‘l’, ‘e’ respectively
Step 19: increment j by 3, i.e. j=j+3
Step 20: end if
Step 21: b[j]=a[i]
Step 22: increment I and j;
Step 23: initialize b array, b[j],b[j+1]…b[j+6] as‘d’, ‘l’,‘e’ ,’e’,‘t’, ‘x’,‘\0’ respectively
Step 24: print frame after stuffing
Step 25: print b
End

CODE:

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h> void
main()
{
inti=0,j=0,n,pos; char

a[20],b[50],ch; clrscr();

printf("enter string\n");

scanf("%s",&a); n=strlen(a);

printf("enter position\n");

scanf("%d",&pos);

if(pos>n)

printf("invalid position, Enter again :");

scanf("%d",&pos);

}
printf("enter the character\n");

scanf("%s",&ch);

b[0]='d'; b[1]='l';

b[2]='e'; b[3]='s';

b[4]='t';b[5]='x';

j=6;

while(i<n)

if(i==pos-1)

b[j]='d';

b[j+1]='l';

b[j+2]='e';

b[j+3]=ch;

b[j+4]='d';

b[j+5]='l';

b[j+6]='e';

j=j+7;

if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')

b[j]='d';

b[j+1]='l';

b[j+2]='e';

j=j+3;
}

b[j]=a[i];
i++;

j++;

b[j]='d'; b[j+1]='l';

b[j+2]='e'; b[j+3]='e';

b[j+4]='t';

b[j+5]='x';

b[j+6]='\0';

printf("\nframe after stuffing:\n");

printf("%s",b); getch();

OUTPUT:

BIT Stuffing program

ALGORITHM:
Begin
Step 1: Read frame length n
Step 2: Repeat step (3 to 4) until i<n(: Read values in to the input frame (0’s and 1’s) i.e.
Step 3: initialize I i=0;
Step 4: read a[i] and increment i
Step 5: Initialize i=0, j=0,count =0
Step 6: repeat step (7 to 22) until i<n
Step 7: If a[i] == 1 then
Step 8: b[j] = a[i]
Step 9: Repeat step (10 to 18) until (a[k] =1 and k<n and count <5)
Step 10: Initialize k=i+1;
Step 11: Increment j and b[j]= a[k];
Step 12: Increment count ;
Step 13: if count =5 then
Step 14: increment j,
Step 15: b[j] =0
Step 16: end if
Step 17: i=k;
Step 18: increment k
Step 19: else
Step 20: b[j] = a[i]
Step 21: end if
Step 22: increment I and j
Step 23: print the frame after bit stuffing
Step 24: repeat step (25 to 26) until i< j
Step 25: print b[i]
Step 26: increment i
End

CODE:
#include<stdio.h>
#include<string.h> void
main()
{

int a[20],b[30],i,j,k,count,n; printf("Enter

frame length:");

scanf("%d",&n);

printf("Enter input frame (0's & 1's only):");

for(i=0;i<n;i++)

scanf("%d",&a[i]);

i=0; count=1; j=0;

while(i<n)

if(a[i]==1)

b[j]=a[i];

for(k=i+1;a[k]==1 && k<n && count<5;k++)

j++;

b[j]=a[k];

count++;

if(count==5)

j++;

b[j]=0; }i=k;

}
else

b[j]=a[i];

}i++;

j++;

printf("After stuffing the frame is:");

for(i=0;i<j;i++) printf("%d",b[i]);

OUTPUT:

2. Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP

CYCLIC REDUNDENCY CHECK PROGRAM

ALGORITHM:
Begin
Step 1: Declare I,j,fr[8],dupfr[11],recfr[11],tlen,flag,gen[4],genl,frl,rem[4]
as integer
Step 2: initialize frl=8 and genl=4
Step 3: initialize i=0
Step 4: Repeat step(5to7) until i<frl
Step 5: read fr[i]
Step 6: dupfr[i]=fr[i]
Step 7:increment i
Step 8: initialize i=0
Step 9: repeat step(10to11) until i<genl
Step 10: read gen[i]
Step 11: increment i
Step 12: tlen=frl+genl-1
Step 13: initialize i=frl
Step 14: Repeat step(15to16) until i<tlen
Step 15: dupfr[i]=0
Step 16: increment i
Step 17: call the function remainder(dupfr)
Step 18: initialize i=0
Step 19: repeat step(20 to 21) until j<genl
Step 20: recfr[i]=rem[j]
Step 21: increment I and j
Step 22: call the function remainder(dupfr)
Step 23: initialize flag=0 and i=0
Step 24: Repeat step(25to28) until i<4
Step 25: if rem[i]!=0 then
Step 26: increment flag
Step 27: end if
Step 28: increment i
Step 29: if flag=0 then
Step 25: print frame received correctly
Step 25: else

Step 25: print the received frame is wrong


End
Function: Remainder(intfr[])
Begin
Step 1: Declare k,k1,I,j as integer
Step 2: initialize k=0;
Step 3: repeat step(4 to 14) until k<frl
Step 4: if ((fr[k] == 1) then
Step 5: k1=k
Step 6: initialize i=0, j=k
Step 7: repeat step(8 to 9) until i<genl
Step 8: rem[i] =fr[j] exponential gen[i]
Step 9: increment I and j
Step 10: initialize I = 0
Step 11: repeat step(12to13) until I <genl
Step 12: fr[k1] = rem[i]
Step 13: increment k1 and i
Step 14: end if
End

CODE:
#include<stdio.h>
#include<conio.h>
remainder(intfr[]);
intgen[4],genl,frl,rem[4];
void main()

{
inti,j,fr[8],dupfr[11],recfr[11],tlen,flag;

clrscr();frl=8;

genl=4;printf("enter frame:");

for(i=0;i<frl;i++)

scanf("%d",&fr[i]);

dupfr[i]=fr[i];

printf("enter generator:");

for(i=0;i<genl;i++)

scanf("%d",&gen[i]);

tlen=frl+genl-1;

for(i=frl;i<tlen;i++)

dupfr[i]=0;

remainder(dupfr);
for(i=0;i<frl;i++)

recfr[i]=fr[i];

for(i=frl,j=1;j<genl;i++,j++)

recfr[i]=rem[j];

}
remainder(recfr);

flag=0;

for(i=0;i<4;i++)

if(rem[i]!=0)

flag++;

if(flag==0)

printf("frame received correctly");

else

printf("the received frame is wrong");

getch();
}

remainder(intfr[])

int k,k1,i,j; for(k=0;k<frl;k++)

if(fr[k]==1)

k1=k;
for(i=0,j=k;i<genl;i++,j++)

rem[i]=fr[j]^gen[i];

for(i=0;i<genl;i++)

fr[k1]=rem[i];

k1++;

OUTPUT:
3. Develop a simple data link layer that performs the flow control using the sliding window protocol,
and loss recovery using the Go-Back-N mechanism.

#include<stdio.h>int
main()
{intw,i,f,frames[50];
printf("Enter window size: "); scanf("%d",&w);

printf("\nEnter number of frames to transmit: "); scanf("%d",&f); printf("\nEnter %d frames: ",f);


for(i=1;i<=f;i++) scanf("%d",&frames[i]); printf("\nWith sliding window protocol the frames will be sent
in the following manner (assuming no corruption of frames)\n\n"); printf("After sending %d frames at each stage
sender waits for acknowledgement sent by the receiver\n\n",w); for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]); printf("Acknowledgement of above frames sent is
received by sender\n\n");
} else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");
return 0; }

OUTPUT:
Enter window size: 10

Enter number of frames to transmit: 3

Enter 3 frames: 15

23

11
With sliding window protocol the frames will be sent in the following manner (assuming no
corruption of frames)

After sending 10 frames at each stage sender waits for acknowledgement sent by the receiver

15 23 11

Acknowledgement of above frames sent is received by sender

4. Implement Dijsktra’s algorithm to compute the shortest path through a network

PROGRAM FOR FINDING SHORTEST PATH

ALGORITHM/FLOWCHART:

Begin
Step1: Declare array path [5] [5], min, a [5][5], index, t[5];
Step2: Declare and initialize st=1,ed=5
Step 3: Declare variables i, j, stp, p, edp
Step 4: print “enter the cost “
Step 5: i=1
Step 6: Repeat step (7 to 11) until (i<=5)
Step 7: j=1
Step 8: repeat step (9 to 10) until (j<=5)
Step 9: Read a[i] [j]
Step 10: increment j
Step 11: increment i
Step 12: print “Enter the path”
Step 13: read p
Step 14: print “Enter possible paths”
Step 15: i=1
Step 16: repeat step(17 to 21) until (i<=p)
Step 17: j=1
Step 18: repeat step(19 to 20) until (i<=5)
Step 19: read path[i][j]
Step 20: increment j
Step 21: increment i
Step 22: j=1
Step 23: repeat step(24 to 34) until(i<=p)
Step 24: t[i]=0
Step 25: stp=st
Step 26: j=1
Step 27: repeat step(26 to 34) until(j<=5)
Step 28: edp=path[i][j+1]
Step 29: t[i]= [ti]+a[stp][edp]
Step 30: if (edp==ed) then
Step 31: break;
Step 32: else
Step 33: stp=edp
Step 34: end if
Step 35: min=t[st]
Step 36: index=st
Step 37: repeat step( 38 to 41) until (i<=p)
Step 38: min>t[i]
Step 39: min=t[i]
Step 40: index=i
Step 41: end if
Step 42: print” minimum cost” min
Step 43: print” minimum cost pth”
Step 44: repeat step(45 to 48) until (i<=5)
Step 45: print path[index][i]
Step 46: if(path[idex][i]==ed) then
Step 47: break
Step 48: end if
End

CODE:

#include<stdio.h>
#include<conio.h> void
main()
{

int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;

clrscr();

printf("enter the cost matrix\n"); for(i=1;i<=5;i++)

for(j=1;j<=5;j++)

scanf("%d",&a[i][j]);

printf("enter the paths\n");

scanf("%d",&p);
printf("enter possible paths\n");

for(i=1;i<=p;i++)

for(j=1;j<=5;j++)

scanf("%d",&path[i][j]);

for(i=1;i<=p;i++)

t[i]=0;

stp=st;

for(j=1;j<=5;j++)

edp=path[i][j+1];

t[i]=t[i]+a[stp][edp]; if(edp==ed)

break;

else

stp=edp;

min=t[st];index=st;

for(i=1;i<=p;i++)

if(min>t[i])

min=t[i];

index=i;
}

printf("minimum cost %d",min); printf("\n

minimum cost path ");

for(i=1;i<=5;i++)

printf("--> %d",path[index][i]);

if(path[index][i]==ed)

break;
}
getch();
}

OUTPUT:
5. Take an example subnet of hosts and obtain a broadcast tree for the subnet.

ALGORITHM:
step 1: declare variable as intp,q,u,v,n; step 2:
Initialize min=99,mincost=0; step 3: declare variable
as int t[50][2],i,j; step 4: declare variable as int
parent[50],edge[50][50]; step 5: Begin step 6: write
"Enter the number of nodes" step 7: read "n" step 8:
Initialize i=0 step 9: repeat step(10-12) until i<n
step10: incrementi step11: write"65+i" step12:
Initialize parent[i]=-1 step13:write "\n"step14:
Initialize i=0 step15: repeat step(15-21) until i<n
step16: increment i step17: write"65+i" step18:
Initialize j=0 step19: repeat until j<n step20:
increment j
step21: read edge[i][j] step22: Initialize i=0 step23:
repeat step(23-43) until i<n step24: increment
istep25: Initialize j=0 step26: repeat until j<n step27:
increment j
step28: if'edge[i]j]!=99
step29: if'min>edge[i][j] repeat step (29-32)
step30: intialize min=edge[i][j] step31:
intialize u=i step32: intialize v=j step33:
calling function p=find(u); step34: calling
function q=find(v);

step35: if'P!=q repeat steps(35-39) step36: intialize t[i][0]=u step37:


intialize t[i][1]=v step38: initialize mincost=mincost+edge[u][v] step39:
call function sunion(p,q) step40: else repeat steps(40-42) step41:
Intialize t[i][0]=-1; step42: Intialize t[i][1]=-1; step43: intialize min=99;
step44; write"Minimum cost is %d\n Minimum spanning tree is",mincost
step45: Initialize i=0 step46: repeat until i<n step47: increment i
step48: if't[i][0]!=-1 && t[i][1]!=-1'repeat step(48-50) step49: write "%c
%c %d", 65+t[i][0], 65+t[i][1], edge[t[i][0]][t[i][1]] step50: write"\n"
step51: end step52: called function sunion(intl,int m) repeat step(51-52)
step53: intialize parent[l]=m step54: called function find(int l) repeat
step(53-56) step55: if parent([l]>0) step56: initialize l=parent step57:
return l

CODE:
#include<stdio.h>intp,
q,u,v,n; int
min=99,mincost=0;
int t[50][2],i,j; int
parent[50],edge[50][50]; main() {
clrscr(); printf("\n Enter the number of
nodes"); scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("%c\t",65+i); parent[i]=-1;
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%c",65+i); for(j=0;j<n;j++)
scanf("%d",&edge[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(edge[i][j]!=99)
if(min>edge[i][j])
{
min=edge[i][j];
u=i;
v=j;
}
p=find(u); q=find(v);
if(p!=q)

{
t[i][0]=u;
t[i][1]=v;mincost=mincost+edge[u][v];
sunion(p,q);
}
else
{
t[i][0]=-1;
t[i][1]=-1;
}
min=99;
}
printf("Minimum cost is %d\n Minimum spanning tree is\n" ,mincost);
for(i=0;i<n;i++) if(t[i][0]!=-
1 && t[i][1]!=-1)
{
printf("%c %c %d", 65+t[i][0], 65+t[i][1],
edge[t[i][0]][t[i][1]]); printf("\n");
}
getch();
}
sunion(intl,int m)
{
parent[l]=m;
}
find(int l)
{
if(parent[l]>0)
l=parent[l];
return l;
}

OUTPUT:

Enter the number of nodes4


A B C D
A2 7 9 3
B3 9 7 2
C3 7 9 2
D4 8 6 7
Minimum cost is 8
Minimum spanning tree is
B D 2
C D 2
D A 4

6. Implement distance vector routing algorithm for obtaining routing tables at each node.
ALGORITHM:
Begin
Step1: Create struct node unsigned dist[20],unsigned from[20],rt[10]
Step2: initialize intdmat[20][20], n,i,j,k,count=0,
Step3: write "the number of nodes "

Step4: read the number of nodes "n"

Step5: write" the cost matrix :"

Step6: intializei=0
Step7: repeat until i<n

Step8: increment i

Step9: initialize j=0

Step10: repeat Step(10-16)until j<n


Step11: increment j
Step12:read dmat[i][j]
Step13:intialize dmat[i][j]=0
Step14:intialize rt[i].dist[j]=dmat[i][j]
Step15:intialize rt[i].from[j]=j
Step16:end
Step17:start do loop Step (17-33)until
Step18:intilialize count =0
Step19:initialize i=0
Step20:repeat until i<n
Step21:increment i
Step22:initialize j=0
Step23:repeat until j<n
Step24:increment j
Step25:initialize k=0
Step26:repeat until k<n
Step27:increment k
Step28:if repeat Step(28-32) until rt[i].dist[j]>dmat[i][k]+rt[k].dist[j]
Step29:intialize rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j]
Step30:intialize rt[i].from[j]=k;
Step31:increment count
Step32:end if
Step33:end do stmt
Step34:while (count!=0)
Step35:initialize i=0
Step36:repeat Steps(36-44)until i<n
Step37:increment i
Step38:write ' state values for router',i+1
Step39:initialize j=0
Step40:repeat Steps ( 40-43)until j<n
Step41:increment j
Step42:write 'node %d via %d distance % ',j+1,rt[i].from[j]+1,rt[i].dist[j]
Step43:end
Step44:end
End

CODE:
#include<stdio.h>struct
node
{ unsigned
dist[20]; unsigned
from[20];
}
rt[10];int
main()

{intdmat[20][20];intn,i,j,k,count=0;printf("
\nEnter the number of nodes :
");scanf("%d",&n);printf("\nEnter the cost
matrix :\n"); for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]); dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j]; rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++) for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k; count++;
}
}while(count!=0);
for(i=0;i<n;i++)
{
printf("\n\nState value for router %d is \n",i+1);
for(j=0;j<n;j++)
{
printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
}

OUTPUT:
Enter the number of nodes : 3

Enter the cost matrix :


1 2 3
4 5 6
7 8 9

State value for router 1 is


node 1 via 1 Distance0
node 2 via 2 Distance2
node 3 via 3 Distance3

State value for router 2 is

node 1 via 1 Distance4


node 2 via 2 Distance0
node 3 via 3 Distance6

State value for router 3 is


node 1 via 1 Distance7
node 2 via 2 Distance8
node 3 via 3 Distance0

7. Implement data encryption and data decryption

#include <stdio.h>

int main()
{inti, x;
char str[100];

printf("\nPlease enter a string:\t");


gets(str);

printf("\nPlease choose following options:\n");


printf("1 = Encrypt the string.\n");
printf("2 = Decrypt the string.\n");
scanf("%d", &x);

//using switch case statements


switch(x)
{
case 1: for(i = 0; (i< 100 &&str[i] !=
'\0'); i++)
str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value

printf("\nEncrypted string: %s\n", str); break;

case 2: for(i = 0; (i< 100 &&str[i] !=


'\0'); i++)
str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to ASCII value

printf("\nDecrypted string: %s\n", str); break;

default:printf("\nError\n");
}
return 0;
}

OUTPUT:
For Encryption:
Please enter a string: EHK
Please choose following options:
1 = Encrypt the string.
2 = Decrypt the string.
1

Encrypted string: HKN

For Decryption:
Please enter a string: HKN
Please choose following options:
1 = Encrypt the string.
2 = Decrypt the string.
2

Decrypted string: EHK

8. Write a program for congestion control using Leaky bucket algorithm.

#include<stdio.h>int
main()
{int incoming, outgoing, buck_size, n, store = 0;
printf("Enter bucket size, outgoing rate and no of inputs: ");
scanf("%d %d %d", &buck_size, &outgoing, &n);

while (n != 0) {printf("Enter the incoming packet size : ");


scanf("%d", &incoming); printf("Incoming packet size %d\n",
incoming); if (incoming <= (buck_size - store)){ store
+= incoming; printf("Bucket buffer size %d out of %d\n",
store, buck_size);
} else {
printf("Dropped %d no of packets\n", incoming - (buck_size - store));
printf("Bucket buffer size %d out of %d\n", store, buck_size); store =
buck_size;
}
store = store - outgoing;
printf("After outgoing %d packets left out of %d in buffer\n", store, buck_size); n--;
}
}

OUTPUT:
Enter bucket size, outgoing rate and no of inputs: 10
10
3
Enter the incoming packet size : 12
Incoming packet size 12
Dropped 2 no of packets
Bucket buffer size 0 out of 10
After outgoing 0 packets left out of 10 in buffer
Enter the incoming packet size : 8
Incoming packet size 8
Bucket buffer size 8 out of 10
After outgoing -2 packets left out of 10 in buffer
Enter the incoming packet size : 12
Incoming packet size 12
Bucket buffer size 10 out of 10
After outgoing 0 packets left out of 10 in buffer
9. Write a program for frame sorting technique used in buffers.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct frame
{intsno; char msg[15]; int
flag; };int main() {inti,j,n,r,k;
printf("enter no of frames\n");
scanf("%d",&n); struct frame
fr[n]; int s[n];
for(i=0;i<n;i++)
{ s[i]=-1;
fr[i].sno=-1;
}
printf("enter the message \n"); for(i=0;i<n;i++)
{
scanf("%s",fr[i].msg); fr[i].sno=i;
}
for(j=0;j<n;j++)
{
r=rand()%n;
if(s[r]==-1)
{fr[j].flag=r;
s[r]=1;

} else
if(s[r]==1)
{
for(k=0;k<n;k++){
r=k;
if(s[r]==-1)
{fr[j].flag=r;
s[r]=1;
break; }
}
}
}

printf("arrived frame are:\n");


printf("\n sno \t msg \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
if(fr[j].flag==i)
{
printf("%d\t%s",fr[j].sno,fr[j].msg); printf("\n");
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{ if(fr[j].sno>fr[j+1].sno)
{struct frame temp;
temp=fr[j];
fr[j]=fr[j+1];
fr[j+1]=temp;
}
}
}
printf("after sorting arrived frames are\n");
printf("\n sno \t msg \n"); for(i=0;i<n;i++)
{
printf("%d\t%s",fr[i].sno,fr[i].msg); printf("\n");
} return
0;
}

output:
enter no of frames
5
enter the message
today
you
have
to
go
arrived frame are:
snomsg 3 to
1 you
2 have
0 today
4 go
after sorting arrived frames are
snomsg 0 today
1 you
2 have
3 to 4
go
10. Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark iii. Viewing
Captured Traffic iv. Analysis and
Statistics & Filters.

Set up the Packet Capture

1. Click View>Wireless Toolbar. The Wireless Toolbar will appear just below the Main toolbar.

2. Use the Wireless Toolbar to configure the desired channel and channel width.
3. Under Capture, click on AirPcap USB wireless capture adapter to select the capture interface.

Note: If the AirPcap isn't listed, press F5 to refresh the list of available packet capture interfaces.

Note: The AirPcap has been discontinued by RiverBed and is 802.11n only.

4. Click the Start Capture button to begin the capture.


5. When you are finished capturing, click the Stopbutton.

Saving the Capture


2. Name the file, and click Save.

Note: .Pcap and .Pcap-ng are good filetypes to use for the capture if you plan to use Eye P.A. to open
the capture.
3. Eye P.A. can now open the capture file.
11. How to run Nmap scan steps
to run Nmap scan

1. Download the Nmap installer.This can be found for free from the developer’s website. It is
highly recommended that you download directly from the developer to avoid any potential
viruses or fake files. Downloading the Nmap installer includes Zenmap, the graphical interface
for Nmap which makes it easy for newcomers to perform scans without having to learn
command lines.
•The Zenmap program is available for Windows, Linux, and Mac OS X. You can find the
installation files for all operating systems on the Nmap website.

2.Install Nmap. Run the installer once it is finished downloading. You will be asked which
components you would like to install. In order to get the full benefit of Nmap, keep all of these
checked. Nmap will not install any adware or spyware.

3. Run the “Nmap – Zenmap” GUI program. If you left your settings at default during
installation, you should be able to see an icon for it on your desktop. If not, look in your Start
menu. Opening Zenmap will start the program.

4. Enter in the target for your scan. The Zenmap program makes scanning a fairly simple
process. The first step to running a scan is choosing your target. You can enter a domain
(example.com), an IP address (127.0.0.1), a network (192.168.1.0/24), or a combination of those.

• Depending on the intensity and target of your scan, running an Nmap scan may be against
the terms of your internet service provider, and may land you in hot water. Always check
your local laws and your ISP contract before performing Nmap scans on targets other
than your own network.
5. Choose your Profile. Profiles are preset groupings of modifiers that change what is
scanned. The profiles allow you to quickly select different types of scans without having to type
in the modifiers on the command line. Choose the profile that best fits your needs:[1]

• Intense scan - A comprehensive scan. Contains Operating System (OS) detection,


version detection, script scanning, traceroute, and has aggressive scan timing. This is
considered an intrusive scan.
• Ping scan - This scan simply detects if the targets are online, it does not scan any ports.
• Quick scan - This is quicker than a regular scan due to aggressive timing and only
scanning select ports.
• Regular scan - This is the standard Nmap scan without any modifiers. It will return ping
and return open ports on the target.

6. Click Scan to start scanning. The active results of the scan will be displayed in the Nmap
Output tab. The time the scan takes will depend on the scan profile you chose, the physical
distance to the target, and the target’s network configuration.

7. Read your results.Once the scan is finished, you’ll see the message “Nmap done” at the
bottom of the Nmap Output tab. You can now check your results, depending on the type of scan
you performed. All of the results will be listed in the main Nmap Output tab, but you can use the
other tabs to get a better look at specific data.[2]

• Ports/Hosts - This tab will show the results of your port scan, including the services
for those ports.

• Topology - This shows the traceroute for the scan you performed. You can see how
many hops your data goes through to reach the target.

• Host Details - This shows a summary of your target learned through scans, such as
the number of ports, IP addresses, hostnames, operating systems, and more.

• Scans - This tab stores the commands of your previously-run scans. This allows you
to quickly re-scan with a specific set of parameters.
12. Operating System Detection using Nmap

Nmap, short for Network Mapper, is a network discovery and security auditing tool. It is known
for its simple and easy to remember flags that provide powerful scanning options. Nmap is
widely used by network administrators to scan for:

• Open ports and services


• Discover services along with their versions

• Guess the operating system running on a target machine

• Get accurate packet routes till the target machine

• Monitoring hosts

Let’s move ahead in this nmap tutorial and discuss the various types of scans.

Nmap Scan Types

A variety of scans can be performed using Nmap. Below are the types of scans:

TCP SCAN

A TCP scan is generally used to check and complete a three-way handshake between you and a
chosen target system. A TCP scan is generally very noisy and can be detected with almost little
to no effort. This is “noisy” because the services can log the sender IP address and might trigger
Intrusion Detection Systems.

UDP SCAN

UDP scans are used to check whether there is any UDP port up and listening for incoming
requests on the target machine. Unlike TCP, UDP has no mechanism to respond with a positive
acknowledgment, so there is always a chance for a false positive in the scan results. However,
UDP scans are used to reveal Trojan horses that might be running on UDP ports or even reveal
hidden RPC services. This type of scan tends to be quite slow because machines, in general, tend
to slow down their responses to this kind of traffic as a precautionary measure.

SYN SCAN

This is another form of TCP scan. The difference is unlike a normal TCP scan, nmap itself crafts
a syn packet, which is the first packet that is sent to establish a TCP connection. What is
important to note here is that the connection is never formed, rather the responses to these
specially crafted packets are analyzed by Nmap to produce scan results.

ACK SCAN

ACK scans are used to determine whether a particular port is filtered or not. This proves to be
extremely helpful when trying to probe for firewalls and their existing set of rules. Simple packet
filtering will allow established connections (packets with the ACK bit set), whereas a more
sophisticated stateful firewall might not.

• FIN SCAN

Also a stealthy scan, like the SYN scan, but sends a TCP FIN packet instead. Most but not all
computers will send an RST packet (reset packet) back if they get this input, so the FIN scan can
show false positives and negatives, but it may get under the radar of some IDS programs and
other countermeasures.

• NULL SCAN

Null scans are extremely stealthy scan and what they do is as the name suggests — they set all
the header fields to null. Generally, this is not a valid packet and a few targets will not know how
to deal with such a packet. Such targets are generally some version of windows and scanning
them with NULL packets may end up producing unreliable results. On the other hand, when a
system is not running windows this can be used as an effective way to get through. XMAS
SCAN
Just like null scans, these are also stealthy in nature. Computers running windows will not
respond to Xmas scans due to the way their TCP stack is implemented. The scan derives its name
from the set of flags that are turned on within the packet that is sent out for scanning. XMAS
scans are used to manipulate the PSH, URG and FIN flags that can be found in the TCP header.

• RPC SCAN

RPC scans are used to discover machines that respond to Remote Procedure Call services (RPC).
RPC allows commands to be run on a certain machine remotely, under a certain set of
connections. RPC service can run on an array of different ports, hence, it becomes hard to infer
from a normal scan whether RPC services are running or not. It is generally a good idea to run an
RPC scan from time to time to find out where you have these services running.

IDLE SCAN

IDLE scan is the stealthiest of all scans discussed in this nmap tutorial, as the packets are
bounced off an external host. Control over the host is generally not necessary, but the host needs
to meet a specific set of conditions. It is one of the more controversial options in Nmap since it
only has a use for malicious attacks.

• Nmap Commands

In this section of Nmap Tutorial, I’ll be listing down the various commands you can use in Nmap
along with their flag and usage description with an example on how to use it. Scanning Techniques
Flag Use Example
-sS TCP syn port scan nmap -sS 192.168.1.1
-sT TCP connect port scan nmap -sT 192.168.1.1
–sU UDP port scan nmap –sU 192.168.1.1

–sA nmap –sA 192.168.1.1


TCP ack port scan

Host Discovery

Flag Use Example


-Pn only port scan nmap -Pn192.168.1.1
-sn only host discover nmap -sn192.168.1.1
-PR arp discovery on a local network nmap -PR192.168.1.1
-n disable DNS resolution nmap -n 192.168.1.1

rt Specification

Flag Use Example


-p specify a port or port range nmap -p 1-30 192.168.1.1
-p- scan all ports nmap -p- 192.168.1.1
-F fast port scan nmap -F 192.168.1.1

Service Version and OS Detection

Flag Use Example


-sV detect the version of services running nmap -sV 192.168.1.1
-A aggressive scan nmap -A 192.168.1.1
-O detect operating system of the target nmap -O 192.168.1.1

Timing and Performance

Flag Use Example


-T0 paranoid IDS evasion nmap -T0 192.168.1.1
-T1 sneaky IDS evasion nmap -T1 192.168.1.1
-T2 polite IDS evasion nmap -T2 192.168.1.1
-T3 normal IDS evasion nmap -T3 192.168.1.1
-T4 aggressive speed scan nmap -T4 192.168.1.1
-T5 insane speed scan nmap -T5 192.168.1.1

NSE Scripts
Flag Use Example
-sC default script scan nmap -sC 192.168.1.1
–script banner banner grabbing nmap –script banner 192.168.1.1

13. Do the following using NS2 Simulator


i. NS2 Simulator-Introduction ii. Simulate to Find the Number of
Packets Dropped iii. Simulate to Find the Number of Packets Dropped
by TCP/UDP iv. Simulate to Find the Number of Packets Dropped due
to Congestion v. Simulate to Compare Data Rate& Throughput.
i . SIMULATION-INTRODUCTION

Network simulation is an important tool in developing, testing and evaluating network protocols.
Simulation can be used without the target physical hardware, making it economical and practical
for almost any scale of network topology and setup. It is possible to simulate a link of any
bandwidth and delay, even if such a link is currently impossible in the real world. With
simulation, it is possible to set each simulated node to use any desired software. This means that
meaning deploying software is not an issue. Results are also easier to obtain and analyze,
because extracting information from important points in the simulated network is as done by
simply parsing the generated trace files.

Simulation is only of use if the results are accurate, an inaccurate simulator is not useful at all.
Most network simulators use abstractions of network protocols, rather than the real thing,
making their results less convincing. S.Y. Wang reports that the simulator OPNET uses a
simplified finite state machine to model complex TCP protocol processing. [19] NS-2 uses a
model based on BSD TCP, it is implemented as a set of classes using inheritance. Neither uses
protocol code that is used in real world networking

Setting up the environment


A user using the NCTUns in single machine mode, needs to do the following steps before he/she
starts the GUI program:

1. Set up environment variables: Before the user can run up the dispatcher, coordinator, or
NCTUns GUI program he/she must set up the NCTUNSHOME environment variable.
2. Start up the dispatcher on terminal 1.
3. Start up the coordinator on terminal 2.
4. Start up the NCTUns client on terminal 3.

After the above steps are followed, the starting screen of NCTUns disappears and the user is
presented with the working window as shown below:
Drawing A Network Topology

To draw a new network topology, a user can perform the following steps:

Choose Menu->File->Operating Mode-> and make sure that the “Draw Topology” mode is
checked. This is the default mode of NCTUns when it is launched. It is only in this mode that a
user can draw a new network topology or change an existing simulation topology. When a user
switches the mode to the next mode “Edit Property”, the simulation network topology can no
longer be changed.

1. Move the cursor to the toolbar


2. Left-Click the router icon on the toolbar.
3. Left-Click anywhere in the blank working area to add a router to the current network topology.
In the same way we can add switch, hub,WLAN access point,WLAN mobile node , wall
(wireless signal obstacle) etc.
4. Left-Click the host icon on the toolbar. Like in step 4, add the required number of hosts to the
current topology
5. To add links between the hosts and the router, left-click the link icon on the toolbar to select it.
6. Left-Click a host and hold the mouse button. Drag this link to the router and then release the
mouse left button on top of the router. Now a link between the selected host and the router has
been created.
7. Add the other, required number of links in the same way. This completes the creation of a
simple network topology
8. Save this network topology by choosing Menu->File->Save. It is saved with a .tpl extension
9. Take the snapshot of the above topology.

Editing Node's Properties


1. A network node (device) may have many parameters to set. For example, we may have to set
the maximum bandwidth, maximum queue size etc to be used in a network interface. For
another example, we may want to specify that some application programs (traffic generators)
should be run on some hosts or routers to generate network traffic.
2. Before a user can start editing the properties of a node, he/she should switch the mode from
the “Draw Topology” to “Edit Property” mode. In this mode, topology changes can no longer
be made. That is, a user cannot add or delete nodes or links at this time.
3. The GUI automatically finds subnets in a network and generates and assigns IP and MAC
addresses to layer 3 network interfaces.
4. A user should be aware that if he/she switches the mode back to the “Draw Topology” mode
when he/she again switches the mode back to the “Edit Topology” mode, node's IP and MAC
addresses will be regenerated and assigned to layer 3 interfaces.
Therefore the application programs now may use wrong IP addresses to communicate with their
partners.

When a user finishes editing the properties of network nodes and specifying application
programs to be executed during a simulation, he/she can start running the simulation.

1. In order to do so, the user must switch mode explicitly from “Edit Property” to “Run
Simulation”. Entering this mode indicates that no more changes can (should) be made to the
simulation case, which is reasonable. This simulation is about to be started at this moment; of
course, any of its settings should be fixed.

2. Whenever the mode is switched to the “ Run Simulation” mode, the many simulation files that
collectively describe the simulation case will be exported. These simulation files will be
transferred to the (either remote or local) simulation server for it to execute the simulation.
These files are stored in the “ main File Name.sim” directory, where main Filename is the
name of the simulation case chosen in the “Draw Topology” mode.

Playing Back the Packet Animation Trace

After the simulation is finished, the simulation server will send back the simulation result
files to the GUI program after receiving these files, the GUI program will store these files in
the “results directory” .It will then automatically switch to “play back mode”.

1. These files include a packet animation trace file and all performance log files that the user
specifies to generate. Outputting these performance log files can be specified by checking
some output options in some protocol modules in the node editor. In addition to this,
application programs can generate their own data files.

2. The packet animation trace file can be replayed later by the packet animation player. The
performance curve of these log files can be plotted by the performance monitor.

Post Analysis

1. When the user wants to review the simulation results of a simulation case that has been
finished before, he /she can run up the GUI program again and then open the case's topology
file.

2. The user can switch the mode directly to the “Play Back” mode. The GUI program will then
automatically reload the results (including the packet animation trace file and performance log
file.

3. After the loading process is finished, the user can use the control buttons located at the bottom
of the screen to view the animation.
Simulation Commands

• Run: Start to run simulation.


• Pause: Pause the currently -running simulation.
• Continue: Continue the simulation that was just paused.
• Stop: Stop the currently -running simulation
• Abort: Abort the currently running simulation. The difference between “stop” and “abort” is
that a stopped simulation job's partial results will be transferred back to GUI files.

• Reconnect: The Reconnect command can be executed to reconnect to a simulation job that was
previously disconnected. All disconnected jobs that have not finished their simulations or have
finished their simulations but the results have not been retrieved back to be a GUI program by
the user will appear in a session table next to the “Reconnect” command. When executing the
reconnect command, a user can choose a disconnected job to reconnect from this session table.

• Disconnect: Disconnect the GUI from the currently running simulation job. The GUI now can
be used to service another simulation job. A disconnected simulation will be given a session
name and stored in a session table.

ii . Simulate to Find the Number of Packets Dropped


AIM:
Simulate a three-node point-to-point network with a duplex link between them. Set the queue size
and vary the bandwidth and find the number of packets dropped.

Sender:- stcp –p 2000 –l 1024 1.0.1.2


Receiver:- rtcp –p 2000 –l 1024
Parameters:- Drop Packets and Collision Packets.

Step1: Drawing topology


1. Select/click the HOST icon on the toolbar and click the left mouse button on the editor, to place
a HOST1 on the editor. Repeat the above procedure and place another host “HOST2” on the
editor.

2. Select/click the HUB icon on the toolbar and click the left mouse button on the editor, to place
HUB1 on the editor.

3. Click on the LINK icon on the toolbar and connect HOST1 to HUB1 and HUB1 to HOST2

4. Click on the “E” icon on the toolbar to save the current topology
e.g: file1.tpl (Look for the ******.tpl extension.)

NOTE: Changes cannot / (should not) be done after selecting the “E” icon

Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to open the HOST window.

2. Select Add button on the HOST window to invoke the command window and provide the
following command in the command textbox.
stg –u 1024 100 1.0.1.2

3. Click OK button on the command window to exit and once again click on the OK button on the
HOST window to exit.

4. Double click the left mouse button while cursor is on HOST2 to open the HOST window.

5. Select Add button on the HOST window to invoke the command window and provide the
following command in the command textbox. rtg –u –w log1

6. Click OK button on the command window to exit.

7. Click NODE EDITOR Button on the HOST window and select the MAC tab from the modal
window that pops up.

8. Select LOG STATISTICS and select checkboxes for Number of Drop Packet and Number of
Collisions in the MAC window

9. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit.

Note: To set QUEUE size


1. Double click the left mouse button while cursor is on HOST2 to open the HOST window.
2. Click NODE EDITOR Button on the HOST window and select the FIFO tab from the modal
window that pops up.

3. Change Queue size (Default 50).

4. Click OK button on the FIFO window to exit and once again click on the OK button on the
HOST window to exit.

Step3: Simulate
i. Click “R” icon on the tool bar

ii. Select Simulation in the menu bar and click/ select RUN in the dropdown list to execute the
simulation.

iii. venTo start playback select “►”icon located at the bottom right corner of the editor.

iv. To view results, Open up new TERMINAL window, move to file1.results folder and open
collision and drop log files in separate TERMINAL window.

Caution: file1 is the hypothetical name given to this simulation. (Refer


Step 1.4)

Changing configurations
Change 1
1. Open the above file,
2. Do not change the topology or any other configuration,
3. Select E icon on the toolbar
4. Reduce the bandwidth at link2 by double clicking the left mouse button while cursor is on link2
.(Change bandwidth on both tabs Uplink/Downlink)
5. Repeat Step3 (Simulate)
Change 2
1. Open the above file,
2. Remove HUB and replace it with SWITCH.
3. Do not change anything in the configuration
Repeat Step3(Simulate)

iii. Simulate to Find the Number of Packets Dropped by TCP/UDP

AIM:
Simulate a four-node point-to-point network and connect the link as follows: Apply a TCP agent
between n0 to n3 and apply a UDP agent between n1 and n3. Apply relevant applications over
TCP and UDP agents changing the parameters and determine the number of packets sent by two
agents.

Topology:-

Sender:- stcp –p 3000 –l


1024 1.0.1.3 stg –u 1024
1.0.1.3

Receiver:- rtcp –p
3000 –l 1024
rtg –u 3000

Parameters:-
Throughput of incoming and outgoing Packets

Step1: Drawing topology


1. Select/click the HOST icon on the toolbar and click the left mouse button on the editor, to place
a host on the editor. Repeat the above procedure and place two other hosts “HOST2” and
“HOST3” on the editor.

2. Select/click the HUB (or SWITCH) icon on the toolbar and click the left mouse button on the
editor, to place a HUB (or SWITCH) on the editor.
3. Click on the LINK icon on the toolbar and connect HOST1 to HUB, HOST2 to HUB and HUB
to HOST3
4. Click on the “E” icon on the toolbar to save the current topology e.g: file2.tpl (Look for the
******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selecting the “E” icon.

Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to open the HOST window.

2. Select Add button on the HOST window to invoke the command window and provide the
following command in the command textbox. stcp –p 21 –l 1024 1.0.1.3

3. Click OK button on the command window to exit

4. Click NODE EDITOR Button on the HOST window and select the MAC tab from the modal
window that pops up.

5. Select LOG STATISTICS and select checkbox for output throughput in the MAC window

6. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit.

7. Double click the left mouse button while cursor is on HOST2 to open the HOST window.

8. Select Add button on the HOST window to invoke the command window and provide the
following command in the command textbox. stg –u 1024 100 1.0.1.3

9. Click OK button on the command window to exit


10. Click NODE EDITOR Button on the HOST window and select the MAC tab from the modal
window that pops up.

11. Select LOG STATISTICS and select checkbox for output throughput in the MAC window

12. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit

13. Double click the left mouse button while cursor is on HOST3 to open the HOST window.

14. Select Add button on the HOST window to invoke the command window and provide the
following command in the command textbox.
rtcp –p 21 –l 1024

15. Click OK button on the command window to exit.

16. Also add the following command on HOST3


rtg –u –w log1

17. Click NODE EDITOR Button on the HOST window and select the MAC tab from the modal
window that pops up.

18. Select LOG STATISTICS and select checkbox for input and output throughput in the MAC
window

19. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit.

Step3: Simulate
i. Click “R” icon on the tool bar
ii. Select Simulation in the menu bar and click/ select RUN in the dropdown list to execute
the simulation.

iii. To start playback select “►” icon located at the bottom right corner of the editor.
iv. To view results, Open up new TERMINAL window, move to file2.results folder and open
input and output throughput log files in separate TERMINAL window.
Caution: file2 is the hypothetical name given to this simulation.
(Refer Step 1.4)

iv. Simulate to Find the Number of Packets Dropped due to Congestion

AIM:
Simulate the transmission of ping messages over a network topology consisting of 6 nodes
and find the number of packets dropped due to congestion.
Topology:-

Sender:- stcp –p 2000 –l


1024 1.0.1.4

Receiver:- rtcp –p
2000 –l 1024

Command Console:-
Goto tools-> simulation time and change Simulation time to 100. During run mode, double
click host 2 and then click command console. And execute the following command.
ping 1.0.1.4

Parameters:-
Drop Packets and Collision Packets.

Step1: Drawing topology


1. Select/click the SUBNET icon on the toolbar and click the left mouse button on the editor, to
place a SUBNET on the editor.

2. A pop up window appears requesting the number of nodes and radius for the subnet
Set number of nodes=6;
Set radius of subnet >150
3. Click on the “E” icon on the toolbar to save the current topology e.g: file4.tpl (Look for the
******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selecting

Step2: Configuration
1. Double click the left mouse button while cursor is on a HOST to open the HOST window.

2. Click NODE EDITOR Button on the HOST window and select the INTERFACE tab (1st tab)
from the
modal window that pops up.

3. Determine the IP address of the selected host.

4. Click OK button on the INTERFACE window to exit and once again click on the OK button on
the HOST window to exit.

5. Repeat the above step for 2 other HOSTS

6. Also click NODE EDITOR Button on the HOST window and select the MAC tab from the
modal window that pops up.

7. Select LOG STATISTICS and select checkbox for drop and collision log statistics in the MAC
window

8. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit.

9. Repeat steps 6 to 9 for the other hosts selected at step 5.


10. Select G_Setting from the menu bar and select Simulation from the drop down list
Set simulation time>600sec

Step3: Simulate
i. Click “R” icon on the tool bar ii. Select Simulation in the menu bar and click/ select RUN in
the dropdown list to execute the simulation.
iii. During simulation, open a new terminal window. iv. Type ping IP
address of a host in the subnet at the command prompt.
v. To view results, Open up new TERMINAL window, move to file4.results folder and open drop
and collision log files in separate TERMINAL window.
Caution: file4 is the hypothetical name given to this simulation.
(Refer Step 1.3)

v. Simulate to Compare Data Rate& Throughput.

AIM:
Simulate an Ethernet LAN using N nodes (6-10), change error rate and data rate and compare
throughput.

Topology:-
Sender:- stcp –p 2000 –l 1024
1.0.1.4

Receiver:-rtcp –p 2000 –l
1024

Double click on receiver link and change BER to 0.000001, Run Again.

Parameters:-
Throughput of outgoing Packets

Step1: Drawing topology


1. Select/click the HOST icon on the toolbar and click the left mouse button on the editor, to place
HOST1 on the editor.
Repeat the above procedure and place 5 other hosts “HOST2”, “HOST3”, “HOST4”, “HOST5”,
and “HOST6”on the editor.

2. Select/click the HUB icon on the toolbar and click the left mouse button on the editor, to place
HUB1 on the editor.
Repeat the above procedure and place another host “HUB2” on the editor

3. Click on the LINK icon on the toolbar and connect HOST1, HOST2 and HOST3 to HUB1,
HOST4, HOST5 and HOST6 to HUB2.
4. Select/click the SWITCH icon on the toolbar and click the left mouse button on the editor, to
place SWITCH1 on the editor.

5. Click on the LINK icon on the toolbar and connect HUB1 to SWITCH1 and HUB2 to
SWITCH1.

6. Click on the “E” icon on the toolbar to save the current topology e.g: file5.tpl (Look for the
******.tpl extension.)
NOTE: Changes cannot / (should not) be done after selecting the “E” icon.

Step2: Configuration
1. Double click the left mouse button while cursor is on HOST1 to open the HOST window.

2. Select Add button on the HOST window to invoke the command window and provide the
following command in the command textbox. stcp –p 21 –l 1024 1.0.1.4

3. Click OK button on the command window to exit and once again click on the OK button on
the HOST window to exit.

4. Repeat this step at HOST 2 and HOST3, but use different commands
stcp –p 21 –l 1024 1.0.1.5 at HOST2
stcp –p 21 –l 1024 1.0.1.6 at HOST3

5. Double click the left mouse button while cursor is on HOST4 to open the HOST window.

6. Select Add button on the HOST window to invoke the command window and provide the
following command in the command textbox.
rtcp –p 21 –l 1024

7. Click OK button on the command window to exit.


8. Click NODE EDITOR Button on the HOST window and select the MAC tab from the modal
window that pops up.

9. Select LOG STATISTICS and select checkbox for output throughput in the MAC window

10. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit.
11. Repeat this step at HOST 5 and HOST6, but use different commands
rtcp –p 21 –l 1024 at HOST5
rtcp –p 21 –l 1024 at HOST6

12. Double click the left mouse button while cursor is on HOST5 to open the HOST window.

13. Click NODE EDITOR Button on the HOST5 window and select the PHYSICAL tab from the
modal window that pops up.

14. Change Bit Error Rate

15. Click OK button on the PHYSICAL window to exit and once again click on the OK button to
return to the HOST window

16. Click NODE EDITOR Button on the HOST window and select the MAC tab from the modal
window that pops up.

17. Select LOG STATISTICS and select checkbox for output throughput in the MAC window

18. Click OK button on the MAC window to exit and once again click on the OK button on the
HOST window to exit.

19. Repeat this step HOST6, Change Bandwidth this time while undoing the change in Bit Error
Rate, also select the output throughput at HOST6.
Step3: Simulate

i. Click “R” icon on the tool bar ii. Select Simulation in the menu bar and click/ select RUN in
the dropdown list to execute the
simulation.

iii. To start playback select “►” icon located at the bottom right iv. To view results, Open up

new TERMINAL window, move to file5.results folder and open


output throughput log files in separate TERMINAL window.

Caution: file5 is the hypothetical name we gave to this simulation


(Refer Step 1.7)

Web Technologies Experiments


1. Write a PHP script to print prime numbers between 1-50.

2. PHP script to a. Find the length of a string. b. Count no of words in a string. c. Reverse a
string. d. Search for a specific string.

3. Write a PHP script to merge two arrays and sort them as numbers, in descending order.

4. Write a PHP script that reads data from one file and write into another file.
5. Develop static pages (using Only HTML) of an online book store. The pages should resemble:

www.amazon.com. The website should consist the following pages. a) Home page

b) Registration and user Login


c) User Profile Page
d) Books catalog
e) Shopping Cart
f) Payment By credit card
g) Order Conformation

6. Validate the Registration, user login, user profile and payment by credit card pages using
JavaScript.
7. Create and save an XML document on the server, which contains 10 users information.
Write a program, which takes User Id as an input and returns the user details by taking the user
information from the XML document.

8. Install TOMCAT web server. Convert the static web pages of assignments 2 into dynamic
web pages using servlets and cookies. Hint: Users information (user id, password, credit card
number) would be stored in web.xml. Each user should have a separate Shopping Cart.

9. Redo the previous task using JSP by converting the static web pages of assignments 2 into
dynamic web pages. Create a database with user information and books information. The books
catalogue should be dynamically loaded from the database. Follow the MVC architecture while
doing the website.
Installation
open terminal sudo apt-get
update enter password sudo apt-
get install php5 sudo apt-get
install lamp-server^
sudo apt-get install tomcat7

1. Write a PHP script to print prime numbers between 1-50.

<?php>

$num = 1 ; while

($num< 50 )
{

$count=0; for (

$i=1;$i<=$num;$i++) { if

(($num%$i)==0) {

$count++;

if ($count==2) {

echo $num." , ";

$num=$num+1;

?>
2. PHP script to
a. Find the length of a string.

b. Count no of words in a string.

c. Reverse a string.

d. Search for a specific string

<html>

<body><?php echo strlen("Hello");

echo "<br>"; echo

str_word_count("Hello world!");

echo "<br>"; echo strrev("Hello

World!"); echo "<br>";

echo strstr("Hello world!","world");

?>

</body>

</html>
3. Write a PHP script to merge two arrays and sort them as numbers, in descending

order<?php

$a1=array(1,30,15,7,25);

$a2=array(4,30,20,41,66);

$num=array_merge($a1,$a2);

array_multisort($num,SORT_DESC,SORT_NUMERIC);

print_r($num)

?>

4.Write a PHP script that reads data from one file and write into another file
<html>

<body>

<?php

$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");

echo fread($myfile,filesize("webdictionary.txt")); fclose($myfile);

?>

</body>

</html>

5)Develop static pages (using Only HTML) of an online book store. The pages should

resemble: www.amazon.com. The website should consist the following pages. Aim:Design

static web pages requird for online book store


a) Home page

Main.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1>Welcome to AMAZON</h1></strong>
<form method="post"action="login.html"target=_blank>
<h4>for books</h4><input type="submit"value="click here">
</form>
</center>
</body>
</html>

output
b) Registration and user Login reg.html:

<html>
<head>
<title>
Registration page</title>
</head>
<body bgcolor="cyan">
<center><strong><h1> AMAZON </h1></strong></center>
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>confirm password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>male &nbsp;&nbsp;
<option >
<input type="radio" name="sex" id="male"></td>
<td><h4>female &nbsp; &nbsp;
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Address</td>
<td><textareaname="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
<td>
<input type="reset" value="reset"></td>
</tr>
</form>
</body>
</html>

Login.html:
<html>
<head>
<title>
login</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1> AMAZON </h1></strong></center>
<right>
<table align="right">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<td></td>
</tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
<td></td>
</tr>
<tr>
<td>
<form method="post" action="catalog.html" >
<input type="submit" value="submit" >
</form>
</td>
<td>
<form method="post" action="reg.html" >
<input type="submit" value="register" >
&nbsp;&nbsp;
<input type="reset" value="reset"></form></td>
</tr>
</table>
</body>
</html>
Userprofile

userprofile.html
<html>
<head>
<title>userprofile</title>
</head>
<body bgcolor="cyan"><center>
<strong><h1>Welcome to AMAZON Online Book Store </h1></strong></center>
Edit your profile here...
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>Edit user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>Edit password</td>
<td><input type="password"></td>
</tr>
<tr>
<option >
<td><h4>male &nbsp;&nbsp;
<input type="radio" name="sex" id="male"></td>
<td><h4>female &nbsp; &nbsp;
<input type="radio" name="sex" id="female" ></td>
</option>
</tr>
<tr>
<td>Edit Address</td>
<td><textareaname="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
</tr>
</form>
</body>
</html>
Books catalog Catalog.html:
<html>
<head>
<title> books
catalog</title>
</head>
<body bgcolor="cyan">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>frontend books</td>
<td></td></tr>
<tr>
<td></td>
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>
<tr>
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
<td></td>
<td><h4>MySql</td>
</tr>
</table>
</h4>
<center>
<b>for buy one of these books
<br>
</b><input type="submit" value="click here">
</center>
</form>
</body>
</html>

Shopping cart

Shopping.html:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="cyan">
<center><h1>
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>
<select >
<optgrouplabel="select the book">
<option value="C&Ds">C&Ds
<option value="Ads">Ads
<option value="Java">Java
<option value="Oracle">Oracle
<option value="Ms SQL Server">Ms SQL Server
<option value="MySql">MySql
</optgroup>
</select>
</td></tr>
<tr>
<td>
Quantity</td>
<td>
<input type="text" id="q">
</td></tr>
<tr>
<td></td>
<td>
<form method=post action="payment.html">
<input type="submit" value=ok />
</form>
</td></tr>
</table>
<center>
<pre>Cost of one book is"500" + shipping "100"</pre>
</center>
<body>
</html>

Payment by credit card

Payment.html:
<html>
<head><title>payment</title></head>
<body bgcolor="cyan">
<center><h1>Payment By Credit Card</h1></center>
<form method=post action="ordrconform.html">
<br><br><br><br><br>
<table align="center">
<tr>
<td>
<h4>Total Amount</h4></td>
<td><input type="text">
</td>
</tr>
<tr>
<td><h4>Credit Card Number</td>
<td><input type="text"></td>
</tr>
<tr>
<td>
</td>
<td><input type="submit" value=OK>
</td>
</tr>
</table>
</form></body>
</html>
Order Conformation

Ordrconform:
<html>
<head><title>order conformation</title></head>
<body bgcolor="cyan">
<center>
<h1><b>BOOK SHOPPING</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body></html>
6 Validate the Registration, user login, user profile and payment by credit card pages using
JavaScript

AIM: Write JavaScript to validate the following fields of the above registration page

<html>
<body
bgcolor="pink"><br><br><br><script
language="javascript"> function
validate()
{ var flag=1;
if(document.myform.id.value==""||
document.myform.pwd.value=="")
{ alert("LoginId and Password must be
filled") flag=0; } if(flag==1)
{ alert("VALID INPUT");
window.open("catalog.html","right");
} else
{
alert("INVALID INPUT"); //document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID:<input type="text" name="id"><br>
PASSWORD:<input type="password" name="pwd"><br><br>
</pre>
<input type="button" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" >
</div>
</form>
</body>
</html>
Profile.html:
<html>
<body
bgcolor="pink"><br><br><script
type="text/javascript"> function
validate() { var flag=1;
if(document.myform.name.value==""||
document.myform.addr.value==""||
document.myform.phno.value==""||
document.myform.id.value==""||
document.myform.pwd.value=="")
{ alert("Enter all the details"); flag=0; }
varstr=document.myform.phno.value; var
x=new RegExp("\\d","g"); if(!(str.match(x))) {
if(!(str.length==10)) flag=0; } var
str1=document.myform.id.value; var x1=new
RegExp("^[A-Z][a-zA-Z]+$","g");
if(!(str1.match(x1))) { flag=0; alert("Invalid
UserID");
}
var str1=document.myform.pwd.value; var
x1=new RegExp("^[A-Z][a-zA-Z]+$","g");
if(!(str1.match(x1))) { flag=0; alert("Invalid
password");
}
if(flag==1)
{ alert("VALID INPUT");
window.self.location.href="login.html";
} else
{
alert("INVALID INPUT"); document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br>
ADDRESS :<input type="type" name="addr"><br>
CONTACT NUMBER:<input type="text" name="phno"><br>
LOGINID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="button" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear"></form></body></html>
Payment by credit card

Payment.html:

<html>
<body
bgcolor="pink"><br><br><br><script
language="javascript"> function
validate()
{ var flag=1; if(document.myform.id.value==""||
document.myform.pwd.value==""|| document.myform.amount.value==""||
document.myform.num.value=="")
{ flag=0; }
varstr=document.myform.amount.value;
var x=new RegExp("\\d","g");
if(!(str.match(x)))
{ flag=0; } var
str1=document.myform.num.value;
var x1=new RegExp("\\d","g");
if(!(str.match(x1)))
{ flag=0; }
if(flag==1)
{ alert("VALID INPUT");
window.self.location.href="order.html";
} else
{
alert("INVALID INPUT"); document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"><br>
AMOUNT :<input type="text" name="amount"><br>
CREDITCARDNUMBER :<input type="PASSWORD" name="num"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="button" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" >
</form>
</body>
</html>

7) Create and save an XML document on the server, which contains 10 users information. Write
a program, which takes User Id as an input and returns the user details by taking the user
information from the XML document.

users.xml

<?xml version="1.0" encoding="UTF-8"?>


<employees>
<employee id="566">
<firstName>niranjan</firstName>
<lastName>reddy</lastName>
<location>Hnk</location>
</employee>
<employee id="567">
<firstName>kishan</firstName>
<lastName>Reddy</lastName>
<location>hzb</location>
</employee>
<employee id="568">
<firstName>lavanya</firstName>
<lastName>xxx</lastName>
<location>hnk</location>
</employee>
<employee id="569">
<firstName>Neelima</firstName>
<lastName>Lakshmi</lastName>
<location>hyd</location>
</employee>
<employee id="570">
<firstName>Abhi</firstName>
<lastName>yyyy</lastName>
<location>wgl</location>
</employee>
<employee id="571">
<firstName>Nikitha</firstName>
<lastName>Reddy</lastName>
<location>krmr</location>
</employee>
<employee id="572">
<firstName>Ashwini</firstName>
<lastName>Reddy</lastName>
<location>hzb</location>
</employee>
<employee id="573">
<firstName>Vinod</firstName>
<lastName>Kumar</lastName>
<location>kzpt</location>
</employee>
<employee id="574">
<firstName>ram</firstName>
<lastName>Reddy</lastName>
<location>MBD</location>
</employee>
<employee id="575">
<firstName>manasa</firstName>
<lastName>reddy</lastName>
<location>hzb</location>
</employee>
</employees>

import org.w3c.dom.*; import javax.xml.parsers.*; import


java.io.*; public class EmployeeParsing { public static
void main(String[] args)throws Exception {
//Get Document Builder
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
//Build Document
Document document = builder.parse(new File("1.xml")); //Normalize the
XML Structure; It's just too important !!
//document.getDocumentElement().normalize();
// TODO Auto-generated method stub
//Here comes the root node
Element root = document.getDocumentElement();
BufferedReaderbr=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter User Id");
String id=br.readLine();
//Get all employees
NodeListnList = document.getElementsByTagName("employee");
System.out.println(root.getNodeName());
System.out.println("============================"); for
(inttemp = 0; temp <nList.getLength(); temp++)
{
Node node = nList.item(temp);
System.out.println(""); //Just a separator if
(node.getNodeType() == Node.ELEMENT_NODE)
{
//Print employee's details of given id Element
eElement = (Element) node;
if(eElement.getAttribute("id").equals(id))
{
System.out.println("Employee id : " + eElement.getAttribute("id")); System.out.println("First
Name : " +
eElement.getElementsByTagName("firstName").item(0).getTextContent());
System.out.println("Last Name : " +
eElement.getElementsByTagName("lastName").item(0).getTextContent());
System.out.println("Location : " +
eElement.getElementsByTagName("location").item(0).getTextContent());
}
}
}
}
}
8)Install TOMCAT web server. Convert the static web pages of assignments 2 into
dynamic web pages using servlets and cookies. Hint: Users information (user id, password,
credit card number) would be stored in web.xml. Each user should have a separate
Shopping Cart.

Web.xml

<?xml version="1.0" encoding="iso-8859-1"?>


<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Servlet Examples</display-name>
<description> Servlet Examples. </description>
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>reg</servlet-class>
</servlet>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet>
<servlet-name>profile</servlet-name>
<servlet-class>profile</servlet-class>
</servlet>
<servlet>
<servlet-name>catalog</servlet-name>
<servlet-class>catalog</servlet-class>
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-pattern>
</servlet>
<servlet>
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>
<url-pattern>order</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>catalog</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>profile</servlet-name>
<url-pattern>profile</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>login</url-pattern>
</servlet-mapping><servlet-mapping>
<servlet-name>reg</servlet-name>
<url-pattern>reg</url-pattern>
</servlet-mapping>
</web-app>

Main.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink">
<br/>
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br/><br/><br/>
<h2 align="center"><pre>
<b>Welcome to online book storage.
Press LOGIN if you are having id
otherwise press REGISTRATION
</b></pre>
</h2>
<br/><br/>
<pre>
<div align="center">
<a href="/tr/login.html">LOGIN</a>
<a href="/tr/reg.html">REGISTRATION</a></div></pre>
</body>
</html>

Login.html

<html>
<body bgcolor="pink"><br/><br/><br/>
<form name="myform" method="post" action="/tr/login">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br/>
PASSWORD :<input type="password" name="pwd" /></pre><br/><br/>
</div>
<br/><br/>
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>

Reg.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br/><br/>
<form name="myform" method="post" action="/tr/reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br/>
ADDRESS :<input type="text" name="addr" /><br/>
CONTACT NUMBER :<input type="text" name="phno" /><br/>
LOGINID :<input type="text" name="id" /><br/>
PASSWORD :<input type="password" name="pwd" /></pre><br/><br/>
</div>
<br/><br/>
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
html PUBLIC "-
Profile.html

<!DOCTYPE //W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br/><br/><br/>
<form name="myform" method="post" action="/tr/profile">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br/>
</pre><br/><br/>
</div>
<br/><br/>
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
html PUBLIC "-

Catalog.html

<!DOCTYPE //W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br/><br/><br/>
<form method="post" action="/tr/catalog">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br/>
</pre><br/><br/>
</div>
<br/><br/>
<div align="center">
<input type="submit" value="ok"
name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" name="button2"/>
</div>
</form>
</body>
</html>
html PUBLIC "-

Order.html

<!DOCTYPE //W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body bgcolor="pink"><br/><br/>
<form method="post" action="/tr/reg">
<div align="center"><pre>
NAME :<input type="text" name="name" /><br/>
PASSWORD :<input type="password" name="pwd" />
TITLE :<input type="text" name="title" /><br/>
NO. OF BOOKS :<input type="text" name="no" /><br/>
DATE :<input type="text" name="date" /><br/>
CREDIT CARD NUMBER:<input type="password" name="cno" /><br
/></pre><br/><br/>
</div>
<br/><br/>
<div align="center">
<input type="submit" value="ok" name="button1"/>
<input type="reset" value="clear" name="button2"/></div>
</form>
</body>
</html>
html PUBLIC "-
java.sql.*;

Login.java

import importjava.io.*; import java.util.*; import javax.servlet.*;


import javax.servlet.http.*; public class login extends HttpServlet{
public void service(HttpServletRequestreq,HttpServletResponseresp)
throws ServletException,IOException { PrintWriter
pw=resp.getWriter(); pw.println("<html><body
bgcolor=\"pink\");
String id=req.getParamenter("id");
String pwd=req.getParameter("pwd");
try {
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select id,password from login";
ResultSetrs=stmt.executeQuery(sqlstmt); intflag=0;
while(rs.next()) {
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2))) {
flag=1;
}
}
if(flag==0) {
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to RETRY</a>");
}
else {
pw.println("VALID LOGIN ID<br><br>");
pw.println("<h3><ul>");
pw.println("<li><ahref=\"profile.html\"><fontcolor=\"black\">USER
PROFILE</font></a></li><br><br>");
pw.println("<li><ahref=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");

pw.println("<li><ahref=\"order.html\"><fontcolor=\"black\">ORDER
CONFIRMATION</font></a></li><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e) { resp.sendError(500,e.toString());
}
}

Reg.java

import importjava.io.*; import java.util.*; import javax.servlet.*;


import javax.servlet.http.*; public class login extends HttpServlet{
public void service(HttpServletRequestreq,HttpServletResponseresp)
java.sql.*;

throws ServletException,IOException {
PrintWriterpw=resp.getWriter(); pw.println("<html><body
bgcolor=\"pink\");
String name=req.getParamenter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
String id=req.getParamenter("id");
String pwd=req.getParameter("pwd");
intno=Integer.parseInt(phno); try {
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select id,password from login";
ResultSetrs=stmt.executeQuery(sqlstmt);
intflag=0; while(rs.next()) {
if(id.equal(rs.getString(1))&&pwd.equals(rs.getString(2))) {
flag=1; }} if(flag==1) {
pw.println("SORRY INVALID ID ALREADY EXITS TRY AGAIN WITH NEW
ID<br><br>");
pw.println("<a href=\"/tr/reg.html\">press REGISTER to RETRY</a>");
}
else {
Statement stmt1=con.createStatement();

stmt1.executeUpdate("insertintologinvalues("+names","+addr+","+no+","+id+","+pwd
+")"); pw.println("YOUR DETAILS ARE ENTERED<br><br>");
pw.println("<a href=\"/tr/login.html\">press LOGIN to login</a>");
}
pw.println("</body></html>");
}
catch(Exception e) { resp.sendError(500,e.toString());
} }}
Catlog.java

import importjava.io.*; import java.util.*; import javax.servlet.*;


import javax.servlet.http.*; public class login extends HttpServlet{
public void service(HttpServletRequestreq,HttpServletResponseresp)
throws ServletException,IOException { PrintWriter
pw=resp.getWriter(); pw.println("<html><body
bgcolor=\"pink\");
String title=req.getParameter("title"); try {
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection
java.sql.*;

con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select id,password from login";
ResultSetrs=stmt.executeQuery(sqlstmt); intflag=0;
while(rs.next()) { pw.println(",div
align=\"center\">"); pw.println("TITLE
:"+rs.getString(1)+"<br>"); pw.println("AUTHOR
:"+rs.getString(2)+"<br>"); pw.println("VERSION
:"+rs.getString(3)+"<br>");
pw.println("PUBLISHER :"+rs.getString(4)+"<br>");
pw.println("COST :"+rs.getString(5)+"<br>");
pw.println("</div"); flag=1;
}
if(flag==0) {
pw.println("SORRY INVALID TITLE TRY AGAIN <br><br>");
pw.println("<a href=\"/tr/catalog.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e) {
resp.sendError(500,e.toString());
}
}
}
Profile.java

import importjava.io.*; import java.util.*; import javax.servlet.*;


import javax.servlet.http.*; public class login extends HttpServlet{
public void service(HttpServletRequestreq,HttpServletResponseresp)
throws ServletException,IOException { PrintWriter
pw=resp.getWriter(); pw.println("<html><body
bgcolor=\"pink\"); String id=req.getParamenter("id");
try {
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=DriverManager.getConnection("jdbc:oracle:thin:
@localhost:1521:orcl","scott","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id="+id+"";
ResultSetrs=stmt.executeQuery(sqlstmt); intflag=0;
pw.println("<br><br><br>"); while(rs.next()) {
pw.println("<div align=\"center\">");
pw.println("NAME :"+rs.getString(1)+"<br>");
java.sql.*;

pw.println("ADDRESS :"+rs.getString(2)+"<br>");
pw.println("PHONE NO :"+rs.getString(3)+"<br>");
pw.println("</div>"); flag=1; }
if(flag==0) {
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"/tr/profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e) {
resp.sendError(500,e.toString());
}
}
}
Order.java

import importjava.io.*; import java.util.*; import javax.servlet.*;


import javax.servlet.http.*; public class login extends HttpServlet{
public void service(HttpServletRequestreq,HttpServletResponseresp)
throws ServletException,IOException { PrintWriter
pw=resp.getWriter(); pw.println("<html><body
bgcolor=\"pink\");
String id=req.getParamenter("id");
String pwd=req.getParameter("pwd");
String title=req.getParameter("title");
String count1=req.getParameter("no");
String date=req.getParameter("date");
String cno=req.getParameter("cno");
intcount=Integer.parseInt(count1); try
{
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d); Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger")
;
Statement stmt=con.createStatement();
java.sql.*;

String sqlstmt="select id,password from


login"; ResultSetrs=stmt.executeQuery(sqlstmt);
intflag=0,amount,x; while(rs.next()) {
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2))) {
flag=1;
}
}
if(flag==0) {
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/order.html\\">press HERE to RETRY</a>");
}
else {
Statement stmt2=con.createStatement();
String s="select cost from book where
title="+title+""; ResultSet rs1=stmt2.executeQuery(s);
intflag1=0; while(rs1.next()) { flag1=1;
x=Integer.parseInt(rs1.getString(1)); amount=count*x;
pw.println("AMOUNT :"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insertintodetailsvalues('"+id+",'"+title+"'+amount+'","'+
cno+'")"'); pw.println("YOUR ORDER has taken<br>");
}
if(flag1==0) {
pw.println("SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\\"/tr/order.html\\">press HERE to RETRY</a>");
}
}
pw.println("</body></html>");
con.close();
}
catch(Exception e) {
resp.sendError(500,e.toString());
}
}
9) Redo the previous task using JSP by converting the static web pages of assignments 2
into dynamic web pages. Create a database with user information and books information.
The books catalogue should be dynamically loaded from the database. Follow the MVC
architecture while doing the website

Main.html:

<html>
<body bgcolor=”pink”>
<br><br><br><br><br><br>
<h1 align=”center”>>U>ONLINE BOOK STORAGE</u></h1><br><br><br>
<h2 align=”center”><PRE><b>
Welcome to online book storage.
Press LOGIN if you are having id
Otherwise press REGISTRATION
</b></PRE></h2>
<br><br><pre>
<div align=”center”><a
href=”/tr/login.html”>LOGIN</a>href=”/tr/login.html”>REGISTRATION</a></div></pre>
</body></html>

Login.html:

<html>
<body bgcolor=”pink”><br><br><br>
<form name="myform" method="post" action=/tr1/login.jsp">
<div align="center"><pre>
LOGIN ID : <input type="passwors" name="pwd"></pre><br><br>
PASSWORD : <input type="password" name="pwd"></pre><br><br></div>
<br><br>
<div align="center">
<input type="submit"value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</input>
<input type="reset" value="clear">
</input>

</div>
</form>
</body>
</html>

Reg.html:
<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/reg.jsp">
<div align="center"><pre>
NAME :<input type="text" name="name"><br>
ADDRESS :<input type="text" name="addr"><br>
CONTACT NUMBER : <input type="text" name="phno"><br>
LOGIN ID : <input type="text" name="id"><br>
PASSWORD : <input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit"value="ok" onClick="validate()">()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div
type="reset" value="clear">
</div>

</form>
</body>
</html>Profile.html:

<html>
<body bgcolor="pink"><br><br>
<form name="myform" method="post" action="/tr1/profile.jsp">
<div align="center"><pre>
LOGIN ID : <input type="text" name="id"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit"value="ok" onClick="validate()">()">
<input type="reset" value="clear">
</form>
</body>
</html>

Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/catalog.jsp">
<div align="center"><pre>
BOOK TITLE : <input type="text" name="title"><br>
</pre><br><br>
</div>
<br><br>
<div align="center"><inputtype="submit"value="ok"
name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<inputtype="reset"value="clear" name=”butt
on2”>
</form>
</body>
</html>Order.html:

<html>
<body bgcolor="pink"><br><br><br>
<form method="post" action="/tr1/order.jsp">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
PASSWORD : <input type="password" name="pwd"><br>
TITLE :<input type="text" name="title"><br>
NO. OF BOOKS : <input type="text" name="no"><br>
DATE : <input type="text" name="date"><br>
CREDIT CARD NUMBER : <input type="password" name="cno"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" name=”button1”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
type="reset"
value="clear" name=”button2”>
</form>
</body>
</html>

Login.jsp:

%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body bgcolor=\”pink\”>”);
String id=request.getParameter(“id”);
String pwd=request.getParameter(“pwd”);
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement();
String sqlstmt=”select id,password from login where id=”+id+” and password=”+pwd+””;
ResultSetrs=stmt.executeQuery(sqlstmt);
int flag=0; while(rs.next())
{ flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID<br><br>”); out.println(“
<a href=\”/tr1/login.html\”>press LOGIN to RETRY</a>”);
} else
{ out.println(“VALID LOGIN
ID<br><br>”);
out.println(“<h3><ul>”);
out.println(“<li><ahref=\”profile.html\”><fontcolor=\”black\”>USER
PROFILE</font></a></li><br><br>”);
out.println(“<li><ahref=\”catalog.html\”><fontcolor=\”black\”>BOOKS
CATALOG</font></a></li><br><br>”);
out.println(“<li><ahref=\”order.html\”><fontcolor=\”black\”>ORDER
CONFIRMATION</font></a></li><br><br>”);
out.println(“</ul>”);
}
out.println(“<body></html>”);
%>

Reg.jsp:

%@page import=”java.sql.*”%
%@page import=”java.io.*”%
<%
out.println(“<html><body bgcolor=\”pink\”>”); String
name=request.getParameter(“name”);
String addr=request.getParameter(“addr”);
String phno=request.getParameter(“phno”);
String id=request.getParameter(“id”);
String pwd=request.getParameter(“pwd”);
intno=Integer.parseInt(phno);
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
Connection con=
DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement();
String sqlstmt=”select id from login”;
ResultSetrs=stmt.executeQuery(sqlstmt);
intflag=0; while(rs.next())
{
if(id.equals(rs.getString(1)))
{
flag=1;
}
}
if(flag==1)
{
out.println(“SORRY LOGIN ID ALREADY EXISTS TRY AGAIN WITH NEW ID <br><br>”);
out.println(“<a href=\”/tr1/reg.html\”>press REGISTER to RETRY</a>”);
}
else
{
Statement stmt1=con.createStatement (); stmt1.executeUpdate (“insert into login values
(“+name+”,”+addr+”,”+no+”,”+id+”,”+pwd+”)”);
out.println (“YOU DETAILS ARE ENTERED <br><br>”); out.println
(“<a href =\”/tr1/login.html\”>press LOGIN to login</a>”);
}
out.println (“</body></html>”);%>

Profile.jsp:

<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body bgcolor=\”pink\”>”);
String id=request.getParameter(“id”);
Driver d=new oracle.jdbc.driver.OracleDriver();
DriverManager.regiserDriver(d);
Connection con=DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement ();
String sqlstmt=”select * from login where id=”+id+””;
ResultSetrs=stmt.executeQuery (sqlstmt); intflag=0;
while(rs.next())
{
out.println (“<div align=\”center\”>”); out.println
(“NAME :”+rs.getString(1)+”<br>”); out.println
(“ADDRESS :”+rs.getString(2)+”<br>”); out.println
(“PHONE NO :”+rs.getString(3)+”<br>”); out.println
(“</div>”); flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”); out.println(“<a
href=\”/tr1/profile.html\”>press HERE to RETRY </a>”);
}
out.println (“</body></html>”);
%>

Catalog.jsp:

<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body bgcolor=\”pink\”>”);
String title=request.getParameter (“title”);
Driver d=new oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement ();
String sqlstmt=”select * from book where title=”+title+””;
ResultSetrs=stmt.executeQuery (sqlstmt); intflag=0;
while(rs.next())
{
out.println (“<div align=\”center\”>”); out.println
(“TITLE :”+rs.getString(1)+”<br>”);
out.println(“AUTHOR :”+rs.getString(2)+”<br>”);
out.println (“VERSION:”+rs.getString(3)+”<br>”);
out.println (“PUBLISHER :” +rs.getString(4)+”<br>”);
out.println (“COST :” +rs.getString(5)+”<br>”);
out.println (“</div>”); flag=1;
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”); out.println(“<a
href=\”/tr1/catalog.html\”>press HERE to RETRY </a>”);
}
out.println (“</body></html>”);
%>

Order.jsp:

<%@page import=”java.sql.*”%>
<%@page import=”java.io.*”%>
<%
out.println (“<html><body bgcolor=\”pink\”>”);
String id=request.getParameter (“id”);
String pwd=request.getParameter (“pwd”);
String title=request.getParameter (“title”);
String count1=request.getParameter (“no”);
String date=request.getParameter (“date”);
String cno=request.getParameter (“cno”);
intcount=Integer.parseInt(count1);
Driver d=new oracle.jdbc.driver.OracleDriver ();
DriverManager.regiserDriver (d);
Connection con=
DriverManager.getConnection (“jdbc:oracle:thin:@localhost:1521:orcl”,”scott”,”tiger”);
Statement stmt=con.createStatement ();
String sqlstmt=”select id, password from login”;
ResultSetrs=stmt.executeQuery (sqlstmt);
intflag=0,amount,x; while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println(“SORRY INVALID ID TRY AGAIN ID <br><br>”); out.println(“<a
href=\”/tr1/order.html\”>press HERE to RETRY </a>”);
}
else
{
Statement stmt2=con.createStatement();
String s=”select cost from book where title=”+title+””;
ResultSet rs1=stmt2.executeQuery(s);
intflag1=0; while(rs1.next())
{ flag1=1;
x=Integer.parseInt(rs1.getString(1));
amount=count*x;
out.println(“AMOUNT :”+amount+”<br><br><br><br>”); Statement
stmt1=con.createStatement ();
stmt1.executeUpdate (“insert into details (“+id+”,”+title+”,”+amount+”,”+date+”,”+cno+”)”);
out.println (“YOU ORDER HAS TAKEN<br>”);
}
if(flag1==0)
{
out.println(“SORRY INVALID BOOK TRY AGAIN <br><br>”); out.println(“<a
href=\”/tr1/order.html\”>press HERE to RETRY </a>”);
}
} out.println (“</body></html>”);
%>

You might also like