You are on page 1of 109

COMPUTER NETWORKS & WEB PROGRAMMING

LAB MANUAL
III Year B.Tech. IT I-Sem

AURORA’S SCIENTIFIC &TECHNOLOGICAL INSTITUTE


(Affiliated to JNTU Hyderabad and Approved by AICTE)
Course Objectives
 To understand the working principle of various communication protocols.
 To understand the network simulator environment and visualize a
network topology and observe its performance
 To analyze the traffic flow and the contents of protocol frames

Course Outcomes
 Implement data link layer farming methods
 Analyze error detection and error correction codes.

 Implement and analyze routing and congestion issues in network design.


 Implement Encoding and Decoding techniques used in presentation layer
 To be able to work with different network tools
COMPUTER NETWORKS PROGRAMS:
PROGRAM 1:
Implement the data link layer framing methods such as character, character-
stuffing and bit stuffing.

Bit stuff program:


#include<stdio.h>
#include<conio.h> void
main()
{
int data[50],count=0,size,i;
clrscr();
printf("Enter the length of the datagram\n");
scanf("%d",&size);
printf("Enter datagram with spaces in between\n");

for(i=0;i<size;i++)
scanf("%d",&data[i]);

printf("Stuffed data is: \n");printf("01111110 ");

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


{
printf("%d",data[i]); data[i]==1 ?
count++ : count=0;if(count==5)
{
printf("0"); count=0;
}
}

printf(" 01111110");
getch();
}
Output:
Enter the length of the
datagram 20
Enter datagram with spaces
in between
111111110011100001
11
Stuffed data is:
011111101111100111110
Byte stuff program:

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

void main()
{
char data[50][2],start[2],end[2];
int size,i;clrscr();
printf("Enter the starting character\n");scanf("%s",start);
printf("Enter the ending character\n");scanf("%s",end);

printf("Enter the length of the datagram\n");scanf("%d",&size);


printf("Enter datagram with spaces in between\n");

for(i=0;i<size;i++)
scanf("%s",data[i]);

printf("Stuffed data is: \n");printf("%c",start[0]);

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


{
if(data[i][0]==start[0] || data[i][0]==end[0])
printf("%c",data[i][0]);
printf("%c",data[i][0]);
}

printf("%c",end[0]);

getch();
}
Output:
Enter the starting
character D
Enter the ending
character G
Enter the length of the
datagram 7
Enter datagram with spaces in between
GOODDAY
Stuffed data is:
DGGOODDDDAYG
PROGRAM 2:
Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and
CRC CCIP

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
int i,j,keylen,msglen,flag=0;
char input[100], key[30],temp[30],quot[100],rem[30],key1[30];

printf("Enter Data:
");
scanf("%s",&input);
printf("Enter Key: ");
scanf("%s",key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for (i=0;i<keylen-1;i++) {
input[msglen+i]='0';
}
for (i=0;i<keylen;i++)
temp[i]=input[i];
for (i=0;i<msglen;i++) {
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0'; else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for (j=keylen-1;j>0;j--) {
if(temp[j]==key[j])
rem[j-1]='0'; else
rem[j-1]='1';
}
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for (i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
printf("\nFinal data is: ");
for (i=0;i<msglen;i++)
printf("%c",input[i]);
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);

printf("\n");
char
temp1[20];
printf("enter recieved
data:"); scanf("%s",temp1);
for (i=0;i<keylen;i++)
temp[i]=temp1[i];
for (i=0;i<msglen;i++) {
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0'; else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for (j=keylen-1;j>0;j--) {
if(temp[j]==key[j])
rem[j-1]='0'; else
rem[j-1]='1';
}
rem[keylen-1]=temp1[i+keylen];
strcpy(temp,rem);
}
strcpy(rem,temp);
printf("\nQuotient is ");
for (i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);

for (i=0;i<keylen-1;i++)
{
if(rem[i]=='1')
flag=1;
else
flag=0;
}
if(flag==0) printf("\
n no error"); else
printf("\nerror is detected");
getch();
}
Output1:
Enter Data: 10110111
Enter Key: 1001

Quotient is 10100011
Remainder is 011
Final data is: 10110111011
enter recieved data:10110111011

Quotient is 10100011
Remainder is
000 no error
output2:
Enter Data: 100100
Enter Key: 1101

Quotient is 111101
Remainder is 001
Final data is: 100100001
enter recieved data:100000001

Quotient is 111010
Remainder is
011 error is
detected
PROGRAM 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()
{
Int w,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: 3
Enter number of frames to transmit:
5 Enter 5 frames: 12 5 89 4 6
With sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)

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

12 5 89
Acknowledgement of above frames sent is received by sender

46
Acknowledgement of above frames sent is received by sender
PROGRAM 4:
Implement Dijsktra’s algorithm to compute the shortest path through a network
#include <limits.h>
#include <stdio.h>
#include
<stdbool.h>

#define V 9

int minDistance(int dist[], bool sptSet[])


{
// Initialize min value
int min = INT_MAX, min_index;

for (int v = 0; v < V; v++)


if (sptSet[v] == false && dist[v] <= min)min =
dist[v], min_index = v;

return min_index;
}

void printSolution(int dist[])


{
printf("Vertex \t\t Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t\t %d\n", i, dist[i]);
}

void dijkstra(int graph[V][V], int src)


{
int dist[V]; // The output array. dist[i] will hold the shortest

bool sptSet[V]; // sptSet[i] will be true if vertex i is included in shortest


for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] = false;

dist[src] = 0;

for (int count = 0; count < V - 1; count++) {


int u = minDistance(dist,

sptSet); sptSet[u] = true;


for (int v = 0; v < V; v++)

if (!sptSet[v] && graph[u][v] && dist[u] !=


INT_MAX && dist[u] + graph[u][v] < dist[v])

dist[v] = dist[u] + graph[u][v];


}

printSolution(dist);
}

int main()
{
/* Let us create the example graph discussed above */
int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
{ 4, 0, 8, 0, 0, 0, 0, 11, 0 },
{ 0, 8, 0, 7, 0, 4, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 4, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 11, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 } };

dijkstra(graph, 0);

return 0;
}
Output:
1.Vertex Distance from Source
2 0 0
3 1 4
4 2 12
5 3 19
6 4 21
7 5 11
8 6 9
9 7 8
10 8 14
PROGRAM 5:
Take an example subnet of hosts and obtain a broadcast tree for the subnet.
#include <stdio.h>

int a[10][10],n;

void main()

int i,j,root;

printf(“Enter no.of nodes:”);

scanf("%d",&n);

printf("Enter adjacent matrix\n");

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

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

printf("Enter connecting of %d–>

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

printf("Enter root

node:");

scanf("%d",&root);
adj(root);
}

adj(int k)

int i,j;

printf("Adjacent node of root node::\n");

printf("%d\n\n",k);

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

if(a[k][j]==1 || a[j][k]==1)

printf("%d\t",j);

printf("\n");

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

if((a[k][j]==0) && (a[i][k]==0) && (i!

=k)) printf("%d",i);

}
Output:
Enter no.of nodes:4
Enter adjacent matrix
Enter connecting of 1–
>1::0 Enter connecting of
1–>2::1 Enter connecting
of 1–>3::1 Enter
connecting of 1–>4::1
Enter connecting of 2–
>1::1 Enter connecting of
2–>2::0 Enter connecting
of 2–>3::1 Enter
connecting of 2–>4::0
Enter connecting of 3–
>1::1 Enter connecting of
3–>2::1 Enter connecting
of 3–>3::1 Enter
connecting of 3–>4::0
Enter connecting of 4–
>1::1 Enter connecting of
4–>2::1 Enter connecting
of 4–>3::1 Enter
connecting of 4–>4::1
Enter root node:2
Adjacent node of root
node:: 2

1 3 4
PROGRAM 6:
Implement distance vector routing algorithm for obtaining routing tables at each
node.

#include<stdio.h>
#include<math.h>
#include<conio.h>
main()
{
int
i,j,k,nv,sn,noadj,edel[20],tdel[2
0][20],min;char
sv,adver[20],ch;
clrscr();
printf("\n ENTER THE NO.OF VERTECES:");
scanf("%d",&nv); printf("\
nENTER THE SOURCE
VERTEXNUMBER AND
NAME:");
scanf("%d",&sn);
flushall(); sv=getchar();
printf("\n NETER NO.OF ADJ
VERTECES TOVERTEX
%c",sv);
scanf("%d",&noadj);
for(i=0;i<noadj;i++)
{
printf("\n ENTER TIME DELAY and NODE NAME:");
scanf("%d %c",&edel[i],&adver[i]);
}
for(i=0;i<noadj;i++)
{
printf("\n ENTER THE TIME DELAY FROM %c to ALL OTHER
NODES:
",adver[i]);
for(j=0;j<nv;j
++)
scanf("%d",&
tdel[i][j]);
}

printf("\n DELAY
VI- VERTEX \n ");
for(i=0;i<nv;i++)
{
min=1000;
ch=0;
for(j=0;j<no
adj;j++)
if(min>(tdel[j
][i]+edel[j]))
{
min=tdel[j][i
]+edel[j];
ch=adver[j];
}
if(i!=sn-1)
printf("\n%d
%
c",min,ch);
else printf("\
n0 -");
}
getch();
}
Output:
ENTER THE NO.OF VERTECES:12

ENTER THE SOURCE VERTEX NUMBER AND NAME:10 J

ENTER NO.OF ADJ VERTECES TO


VERTEX 4 ENTER TIME

DELAY and NODENAME:8

A ENTER TIME DELAY and

NODENAME:10 I ENTER

TIME DELAY and NODE

NAME:12 H ENTER TIME

DELAY and NODE NAME:6

ENTER THE TIME DELAY FROM A to


ALL OTHERNODES: 0 12 25 40 14 23
18
17 21 9 24 29

ENTER THE TIME DELAY FROM I to


ALL OTHERNODES: 24 36 18 27 7 20
31
20 0 11 22 33

ENTER THE TIME DELAY FROM H to


ALL OTHERNODES: 20 31 19 8 30 19 6
0
14 7 22 9

ENTER THE TIME DELAY FROM K to


ALL OTHERNODES: 21 28 36 24 22 40
31 19 22 10 0 9
PROGRAM 7:
Implement data encryption and data decryption

#include<stdio.h>
#include<math.h>
double min(double x, double y)
{
return(x<y?x:y);
}
double max(double x,double y)
{
return(x>y?x:y);
}
double gcd(double x,double y)
{
if(x==y)
return(x);
else
return(gcd(min(x,y),max(x,y)-min(x,y)));
}
long double modexp(long double a,long double x,long double n)
{
long double r=1;

while(x>0)
{
if ((int)(fmodl(x,2))==1)
{
r=fmodl((r*a),n);
}

a=fmodl((a*a),n);
x/=2;
}
return(r);
}
int main()
{
long double
p,q,phi,n,e,d,cp,cq,dp,dq,mp,mq,sp,sq,rp,rq,qInv,h; long
double ms,es,ds;
do{
printf("\n Enter prime numbers p and
q:"); scanf(" %Lf %Lf",&p,&q);
}
while(p==q);
n=p*q;
phi=(p-1)*(q-1);

do{
printf("\n Enter prime value of
e:"); scanf(" %Lf",&e);
}
while((gcd(e,phi)!=1)&&e>phi); /*for e being relatively prime to
phi */

for(d=1;d<phi;++d)
{
if(fmod((e*d),phi)==1)
break;
}
printf("\n D within main = %Lf",d);

/* public key is {n,e} private key is d */


printf("\n Enter the
message:"); scanf("
%Lf",&ms);

es=modexp(ms,e,n);
ds=modexp(es,d,n);

printf("\n Original Message : %Lf",ms);


printf("\n Encrypted Message : %Lf",es);
printf("\n Decrypted Message : %Lf\
n",ds);

return(0);
}
Output:
Enter prime numbers p and q:223
101 Enter prime value of e:2213
D within main = 18077.000000
Enter the message:123
Original Message :
123.000000
Encrypted Message :
18415.000000 Decrypted Message
: 123.000000
PROGRAM 8:
Write a program for congestion control using Leaky bucket algorithm.

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

#define NOF_PACKETS 10

int rand1(int a)
{
int rn = (random() % 10) %
a; return rn == 0 ? 1 : rn;
}

int main()
{
int packet_sz[NOF_PACKETS], i, clk, b_size, o_rate, p_sz_rm=0, p_sz, p_time, op;
for(i = 0; i<NOF_PACKETS; ++i)
packet_sz[i] = rand1(6) * 10;
for(i = 0; i<NOF_PACKETS; +
+i)
printf("\npacket[%d]:%d bytes\t", i,
packet_sz[i]); printf("\nEnter the Output rate:");
scanf("%d", &o_rate);
printf("Enter the Bucket
Size:"); scanf("%d", &b_size);
for(i = 0; i<NOF_PACKETS; ++i)
{
if( (packet_sz[i] + p_sz_rm) > b_size)
if(packet_sz[i] > b_size)/*compare the packet siz with bucket size*/ printf("\n\
nIncoming packet size (%dbytes) is Greater than bucket capacity
(%dbytes)-PACKET REJECTED", packet_sz[i], b_size);
else
printf("\n\nBucket capacity exceeded-PACKETS REJECTED!!");
else
{
p_sz_rm += packet_sz[i];
printf("\n\nIncoming Packet size: %d", packet_sz[i]);
printf("\nBytes remaining to Transmit: %d", p_sz_rm);
p_time = rand1(4) * 10;
printf("\nTime left for transmission: %d units", p_time);
for(clk = 10; clk <= p_time; clk += 10)
{
sleep(1);
if(p_sz_rm)
{
if(p_sz_rm <= o_rate)/*packet size remaining comparing with output
rate*/
op = p_sz_rm, p_sz_rm =
0; else
op = o_rate, p_sz_rm -= o_rate; printf("\
nPacket of size %d Transmitted", op);
printf("- - -Bytes Remaining to Transmit: %d", p_sz_rm);
}
else
{
printf("\nTime left for transmission: %d units", p_time-clk); printf("\
nNo packets to transmit!!");
}
}
}
}
}
Output:
packet[0]:30 bytes
packet[1]:10 bytes
packet[2]:10 bytes
packet[3]:50 bytes
packet[4]:30 bytes
packet[5]:50 bytes
packet[6]:10 bytes
packet[7]:20 bytes
packet[8]:30 bytes
packet[9]:10 bytes
Enter the Output rate:15
Enter the Bucket Size:10
Incoming packet size (30bytes) is Greater than bucket capacity (10bytes)-PACKET
REJECTED

Incoming Packet size: 10


Bytes remaining to Transmit: 10
Time left for transmission: 20
units
Packet of size 10 Transmitted----Bytes Remaining to Transmit: 0
Time left for transmission: 0
units No packets to transmit!!

Incoming Packet size: 10


Bytes remaining to Transmit: 10
Time left for transmission: 30
units
Packet of size 10 Transmitted----Bytes Remaining to Transmit: 0
Time left for transmission: 10
units No packets to transmit!!

Time left for transmission: 0


units No packets to transmit!!
Incoming packet size (50bytes) is Greater than bucket capacity (10bytes)-PACKET
REJECTED

Incoming packet size (30bytes) is Greater than bucket capacity (10bytes)-PACKET


REJECTED

Incoming packet size (50bytes) is Greater than bucket capacity (10bytes)-PACKET


REJECTED

Incoming Packet size: 10


Bytes remaining to Transmit: 10
Time left for transmission: 10
units
Packet of size 10 Transmitted----Bytes Remaining to Transmit: 0

Incoming packet size (20bytes) is Greater than bucket capacity (10bytes)-PACKET


REJECTED

Incoming packet size (30bytes) is Greater than bucket capacity (10bytes)-PACKET


REJECTED

Incoming Packet size: 10


Bytes remaining to Transmit: 10
Time left for transmission: 10
units
Packet of size 10 Transmitted----Bytes Remaining to Transmit: 0
PROGRAM 9:
Write a program for frame sorting technique used in buffers.
#include<stdlib.h>

struct frame{

int fslno;

char finfo[20];

};

struct frame arr[10];

int n;

void sort()

int i,j,ex;

struct frame temp;

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

ex=0;

for(j=0;j<n-i-1;j++)

if(arr[j].fslno>arr[j+1].fslno)

temp=arr[j];

arr[j]=arr[j+1];
arr[j+1]=temp;

ex++;

if(ex==0) break;

void main()

int i;

printf("\n Enter the number of frames \

n"); scanf("%d",&n);

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

{
arr[i].fslno=random();

printf("\n Enter the frame contents for sequence number %d\n",arr[i].fslno);

scanf("%s",arr[i].finfo);

sort();

printf("\n The frames in sequence \n");


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

printf("\n %d\t%s \n",arr[i].fslno,arr[i].finfo);

}
Output:
Enter the number of frames
4
Enter the frame contents for sequence number
1804289383 write
Enter the frame contents for sequence number
846930886 do
Enter the frame contents for sequence number
1681692777 nw
Enter the frame contents for sequence number
1714636915 mute
The frames in

sequence 846930886

do

1681692777 nw

1714636915 mute

1804289383 write
PROGRAM 10.
Wireshark
i. Packet Capture Using Wire shark
ii. Starting Wire shark
iii. Viewing Captured Traffic
iv. Analysis and Statistics & Filters.
1. CLICK TO DOWNLOAD WIRESHARK

2. SETUP OF WIRESHARK
3.CHOOSE COMPONENTS

4. CHOOSE INSTALL LOCATION


5. LICENSE AGREEMENT

6. ADDITIONAL TASK
Packet Capture Using Wire shark

Analysis and Statistics & Filters.


PROGRAM 11:
How to run Nmap scan

CLICK DOWNLOAD NMAP

OPEN CMD PROMPT AND TYPE NMAP


PROGRAM 12:
Operating System Detection using Nmap

OPEN CMD PROMPT AND START NMAP

ENTER IP ADDRESS OF SYSTEM AND IT SHOWS THE OPERATING


SYSTEM DETAILS
PROGRAM 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
Simulate to Find the Number of Packets Dropped

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


WEB PROGRAMMING:
PROGRAM 1:
Write a html program for Creation of web site with forms, frames, links, tables
etc.

Home.html
<html>
<head>
<title>Home</title>
</head>
<frameset rows="25%,*">
<frame src="frame1.html">
<frameset cols="25%,*">
<frame src="frame2.html" name="f2">
<frame src="frame3.html" name="f3">
</frameset>
</html>

Frame1.html
<html>
<head><title>frame1</title>
</head>
<body bgcolor="blue">
<h1 style="color.green;font-size:15pt">
<marquee bgcolor="#cccccc" loop="-1" scrollamount="6" width="100%">
AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE </marquee>
</h1>
</body>
</html>
Frame2.html
<html>
<head><title>frame2</title>
<style type="text/css">
h1
{
font-size:25pt;color:pink;
}
</style>
</head>
<body bgcolor="red">
<h1>click the link</h1>
<a href="intro.html" target=f3>Introduction</a><br>
<a href="dept.html" target=f3>Departments</a><br>
<a href="ad.html" target=f3>ADDRESS</a><br>
<a href="feed.html" target=f3>Feedback</a><br>
<a href="gall.html" target=f3>Gallery</a><br>
</body>
</html>
Frame3.html
<html>
<head><title>1st page</title>
<link rel="stylesheet" type="text/css" href="C:\Documents and
Settings\Administrator\Desktop\ab\css1.css"/>
</head>
<body bgcolor="tan">
<h2><center>YOU ARE IN HOME PAGE</center></h2>
</body>
</html>

Intro.html
<html>
<head><title>intro</title>
</head>
<body bgcolor="black">
<font color=red>
<p>
Welcome to AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE <br>
<br>
“AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE resolves to mould
a human task force useful to the society through transparent methods that
lead to continuous improvement of the resources and state-of-the-art
methodologies conforming to recognized standards.”
</p>
</font>
</body>
</html>

Ad.html
<html>
<head><title>ADDRESS</title>
</head>
<body bgcolor="black">
<p>
<font color=red>
Name:AURORA’S TECHNOLOGICAL AND RESEARCH INSTITUTE
Location:Hyderabad<br>
Contact No:040-29888909<br>
Website: www.atri.edu.in<br>
</font>
</p>
</body>
</html>
Dept.html
<html>
<head><title>Departments</title>
</head>
<body>
<div align="center">
<table border=2>
<tr>
<th>Dept code</th>
<th>Dept name</th>
</tr>
<tr>
<td>01</td>
<td>CSE</td>
</tr>
<tr>
<td>02</td>
<td>IT</td>
</tr>
<tr>
<td>03</td>
<td>EEE</td>
</tr>
<tr>
<td>04</td>
<td>IT</td>
</tr>
<tr>
<td>05</td>
<td>MECH</td>
</tr>
<tr>
<td>06</td>
<td>AI/ML</td>
</tr>
</table>
</div>
</body>
</html>

Feed.html
<html>
<head><title>feed</title>
</head>
<body bgcolor="black">
<p>
<font color=green>
To give your feedback mail to google_feedback@edu.in
</font>
</p>
</body>
</html>
Gall.html
<html>
<head><title>gall</title>
</head>
<body bgcolor="pink">
<p>
<font color=blue>
College Front View</font>
</p>
<imgsrc="file:///d:/google.JPG" height="300" width="400"/>
</body>
</html>
OUTPUT:
PROGRAM 2:
Design a web site using HTML and DHTML. Use Basic text Formatting, Images
<html>
<head>
<body>
<center>
<script type = "text/Javascript"> var a = "Information";
document.write("<h2>" + a + "Technology" + "</h2>");
</script>
</center>
</body>
<title> Pseudo Classes for Hyperlinks </title><style type =
"text/css">a.col:link{color:blue} a.col:visited{color:black}
a.col:hover{color:orange}
a.big:link{color:skyblue}
a.big:visited{color:brown} a.big:hover{font-size:200%} </style>
</head>
<body>
<h3> Move the mouse over the text </h3><p>
<em>
<a class = "col" href = "form2.html" target = "_blank"> The text changes
the color</a></em>
</p>
<p>
<em>
<a class = "big" href = "form2.html" target = "_blank"> The
text is getting big in size </a>
</em>
</p>
</body>
</html>
Output:
PROGRAM 3:
Create a script that asks the user for a name, then greets the user with "Hello"
and the username on the page

<html>
<body>
<script>

var name = prompt("Please enter your


name:"); console.log("Hello " + name);

</script>
</body>
</html>
Output:
Hello tom
PROGRAM 4:
Create a script that collects numbers from a page and then adds them up and
prints them to a blank field on the page
<html>
<body>
<div>
<div>
<h1>Add two number using text box as input using javascript</h1>
</div>
Enter First Number :<br>
<input type="text" id="Text1" name="TextBox1">
<br>
Enter Second Number :<br>
<input type="text" id="Text2" name="TextBox2">
<br>
Result :<br>
<input type="text" id="txtresult" name="TextBox3">
<br>
<input type="button" name="clickbtn" value="Display Result" onclick="add_number()">

<script type="text/javascript">
function add_number(){
var first_number = parseInt(document.getElementById("Text1").value);
var second_number =
parseInt(document.getElementById("Text2").value); var result =
first_number + second_number;
document.getElementById("txtresult").innerHTML = result;
}
</script>
</html>
Output:
PROGRAM 5:
Create a script that prompts the user for a number and then counts from 1 to that
number displaying only the odd numbers

<html>
<body>
<h1>JS Find All Odd Numbers</h1>

<script>
var start = 10;
var end = 25;

document.write("Odd numbers between "+start+" to "+end+":<br>");


for(start = start; start <= end; start++)
{
if(start % 2 != 0)
document.write(start +", ");
}
</script>
</body>
</html>
Output:
JS Find All Odd Numbers
Odd numbers between 10 to 25:
11 13 15 17 19 21 23 25
PROGRAM 6:
Create a script that will check the field in Assignment 1 for data and alert the
user if it is blank. This script should run from a button
<html>
<head>
<script type =
"text/javascript">
function fun() {

alert ("This is an alert dialog box");


}
</script>
</head>

<body>
<p> Click the following button to see the effect </p>
<form>
<input type = "button" value = "Click me" onclick = "fun();" />
</form>
</body>
</html>
Output:
PROGRAM 7:

Using CSS for creating web sites


<!DOCTYPE html>

<!-- Created By CodingNepal - www.codingnepalweb.com -->

<html lang="en" dir="ltr">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!------<title> Website Layout | CodingLab</title>------>

<link rel="stylesheet" href="style.css">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css"/>

</head>

<body>

<nav>

<div class="menu">

<div class="logo">

<a href="#">CodingLab</a>

</div>

<ul>

<li><a href="#">Home</a></li>

<li><a href="#">About</a></li>

<li><a href="#">Services</a></li>

<li><a href="#">Contact</a></li>

<li><a href="#">Feedback</a></li>

</ul>

</div>

</nav>

<div class="img"></div>

<div class="center">
<div class="title">Create Amazing Website</div>

<div class="sub_title">Pure HTML & CSS Only</div>

<div class="btns">

<button>Learn More</button>

<button>Subscribe</button>

</div>

</div>

@import
url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');

*{

margin: 0;

padding: 0;

box-sizing: border-box;

font-family: 'Poppins',sans-serif;

::selection{

color: #000;

background: #fff;

nav{

position: fixed;

background: #1b1b1b;

width: 100%;

padding: 10px 0;

z-index: 12;

nav .menu{

max-width: 1250px;

margin: auto;

display: flex;
align-items: center;

justify-content: space-between;

padding: 0 20px;

.menu .logo a{

text-decoration: none;

color: #fff;

font-size: 35px;

font-weight: 600;

.menuul{

display: inline-flex;

.menuul li{

list-style: none;

margin-left: 7px;

.menuulli:first-child{

margin-left: 0px;

.menuul li a{

text-decoration: none;

color: #fff;

font-size: 18px;

font-weight: 500;

padding: 8px

15px; border-

radius: 5px;

transition: all 0.3s ease;


}
.menuul li

a:hover{ backgrou

nd: #fff; color:

black;

.img{

background: url('img3.jpg')no-repeat;

width: 100%;

height: 100vh;

background-size: cover;

background-position: center;

position: relative;

.img::before{

content: '';

position: absolute;

height: 100%;

width: 100%;

background: rgba(0, 0, 0, 0.4);

.center{

position: absolute;

top: 52%;

left: 50%;

transform: translate(-50%, -50%);

width: 100%;

padding: 0 20px;

text-align:

center;
}

.center .title{
color: #fff;

font-size: 55px;

font-weight: 600;

.center .sub_title{

color: #fff;

font-size: 52px;

font-weight: 600;

.center .btns{ marg

in-top: 20px;

.center .btns button{

height: 55px;

width: 170px;

border-radius: 5px;

border: none;

margin: 0 10px;

border: 2px solid

white; font-size: 20px;

font-weight: 500;

padding: 0

10px; cursor:

pointer; outline:

none;

transition: all 0.3s ease;

.center .btnsbutton:first-child{

color: #fff;
background: none;
}

.btnsbutton:first-child:hover{

background: white;

color: black;

.center .btnsbutton:last-child{

background: white;

color: black;

</body>

</html>
Output:
PROGRAM 8:

Creating simple application to access data base using JDBC Formatting HTML
with CSS

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class JDBCExample {

static final String DB_URL = "jdbc:mysql://localhost/";

static final String USER = "guest";

static final String PASS =

"guest123"; public static void

main(String[] args) {

// Open a connection

try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

Statement stmt = conn.createStatement();

<i>DATABASE STUDENTS</i>

String sql = "CREATE DATABASE STUDENTS";

stmt.executeUpdate(sql);

System.out.println("Database created

successfully...");

} catch (SQLException e)

{ e.printStackTrace();

}
Output:

C:\>javac
JDBCExample.java C:\>

When you run JDBCExample, it produces the following result –

C:\>java JDBCExample
Database created successfully...
C:\>
PROGRAM 9:

Program for manipulating Databases and SQL.

//import statements...

public class Main {

private static final String JDBC_DRIVER =

"com.mysql.jdbc.Driver"; private static final String

DATABASE_URL = "jdbc:mysql://localhost/hr";

private static final String USERNAME = "admin"; private

static final String PASSWORD = "secret"; public static void

createTable(){

Connection connection = null; Statement statement = null; try {

Class.forName(JDBC_DRIVER);

connection = DriverManager.getConnection(DATABASE_URL,

USERNAME,

PASSWORD);

statement = connection.createStatement();

//boolean b=statement.execute("DROP TABLE IF EXISTS

emp"); boolean b=statement.execute("CREATE TABLE emp(id

int primary key,name varchar(15),department int,salary

int,location varchar(20))"); if(b==true)

System.out.println("Tables created..."); } catch (SQLExceptionsqlEx){

sqlEx.printStackTrace();

System.exit(1);

} catch (ClassNotFoundExceptionclsNotFoundEx) {

clsNotFoundEx.printStackTrace();
System.exit(1); } finally {

try { statement.close(); connection.close();

} catch (Exception e) { System.exit(1);

public static void createEmployee(int id, String name, int dept, int

sal, String loc){

Connection connection = null; PreparedStatement

preparedStatement = null; try {

Class.forName(JDBC_DRIVER);

connection = DriverManager.getConnection(DATABASE_URL,

USERNAME,PASSWORD);

preparedStatement = connection.prepareStatement("INSERT

INTO emp VALUES(?,?,?,?,?)");

preparedStatement.setInt(1, id); preparedStatement.setString(2, name);

preparedStatement.setInt(3, dept); preparedStatement.setInt(4, sal);

preparedStatement.setString(5, loc); boolean

b=preparedStatement.execute(); if(b==true)

System.out.println("1 record inserted...");

} catch (SQLExceptionsqlEx) { sqlEx.printStackTrace();

System.exit(1);

} catch (ClassNotFoundExceptionclsNotFoundEx) {

clsNotFoundEx.printStackTrace();

System.exit(1); } finally {

try {
preparedStatement.close();

connection.close();

} catch (Exception e) { System.exit(1);

public static void updateSalary(int id, int raise){ Connection

connection = null; PreparedStatementpreparedStatement = null;

try {

Class.forName(JDBC_DRIVER);

connection = DriverManager.getConnection(DATABASE_URL,

USERNAME,PASSWORD);

preparedStatement = connection.prepareStatement("UPDATE

emp SET salary=salary+? WHERE id=?");

preparedStatement.setInt(1, raise); preparedStatement.setInt(2,

id); boolean b=preparedStatement.execute(); if(b==true)

System.out.println("$"+raise+" raised for emp id="+id);

} catch (SQLExceptionsqlEx) { sqlEx.printStackTrace();

System.exit(1);

} catch (ClassNotFoundExceptionclsNotFoundEx) {

clsNotFoundEx.printStackTrace();

System.exit(1); } finally {

try { preparedStatement.close(); connection.close();

} catch (Exception e) { System.exit(1);

}
}

public static void deleteEmployee(int id){ Connection connection

= null; PreparedStatementpreparedStatement = null; try{

Class.forName(JDBC_DRIVER);

connection = DriverManager.getConnection(DATABASE_URL,

USERNAME,PASSWORD);

preparedStatement = connection.prepareStatement("DELETE

FROM emp WHERE id=?");

preparedStatement.setInt(1, id)

boolean b=preparedStatement.execute();

if(b==true) System.out.println("1 record

deleted...");

} catch (SQLExceptionsqlEx) { sqlEx.printStackTrace();

System.exit(1);

} catch (ClassNotFoundExceptionclsNotFoundEx) {

clsNotFoundEx.printStackTrace();

System.exit(1); } finally {

try { preparedStatement.close(); connection.close();

} catch (Exception e) { System.exit(1);

}}}

public static void readEmployees() { Connection connection = null;

Statement statement = null;

try { Class.forName(JDBC_DRIVER);

cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in


connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,

PASSWORD);

statement = connection.createStatement();

ResultSetresultSet = statement.executeQuery("SELECT * FROM

emp"); ResultSetMetaDatametaData = resultSet.getMetaData();

int noCols = metaData.getColumnCount(); for (int i = 1; i<= noCols; i++) {

if (i != 3) System.out.printf("%-10s\t",

metaData.getColumnName(i).toUpperCase());

System.out.println(); while (resultSet.next())

{ for (int i = 1; i<= noCols; i++) { if (i != 3)

System.out.printf("%-10s\t", resultSet.getObject(i));

System.out.println();

} catch (SQLExceptionsqlEx) { sqlEx.printStackTrace();

System.exit(1);

} catch (ClassNotFoundExceptionclsNotFoundEx) {

clsNotFoundEx.printStackTrace();

System.exit(1);

} finally { try {

statement.close();

connection.close();

} catch (Exception e) { System.exit(1);

}
}

public static void readEmployee(int id) { Connection connection =

null; Statement statement = null;

try { Class.forName(JDBC_DRIVER);

connection = DriverManager.getConnection(DATABASE_URL,

USERNAME,

PASSWORD);

statement = connection.createStatement();

ResultSetresultSet = statement.executeQuery("SELECT *

FROM emp WHERE id="+id);

ResultSetMetaDatametaData = resultSet.getMetaData(); int noCols =

metaData.getColumnCount();

for (int i = 1; i<= noCols; i++) { if (i != 3) System.out.printf("%-

10s\t",

metaData.getColumnName(i).toUpperCase());

System.out.println();

while (resultSet.next()) {

for (int i = 1; i<= noCols; i++) { if (i != 3)

System.out.printf("%-10s\t",

resultSet.getObject(i));

System.out.println();

} catch (SQLExceptionsqlEx) { sqlEx.printStackTrace();

System.exit(1);
} catch (ClassNotFoundExceptionclsNotFoundEx) {
clsNotFoundEx.printStackTrace();

System.exit(1);

} finally { try {

statement.close();

connection.close();

} catch (Exception e) { System.exit(1);

public static void main(String[] args) {


//createTable();

createEmployee(1234, "Larson", 123, 1200, "New Jersey");


createEmployee(5678, "Jones", 123, 1100, "New Jersey");
createEmployee(7890, "Kapil", 345, 1600, "Los Angeles");
createEmployee(2341, "Myers", 123, 1800, "New Jersey");
createEmployee(6784, "Bruce", 345, 2200, "Los Angeles");
createEmployee(9636, "Neumann", 123, 3200, "New Jersey");
updateSalary(1234, 1000);
createEmployee(1111, "Lee", 123, 4400, "New Jersey");
deleteEmployee(1111);
readEmployees();
readEmployee(6784);
}
}
Output:
Thus the manipulating the Database and SQL executed successfully
PROGRAM 10:
Program using PHP database functions.

Index.html
<html>
<body>
<form action="insert.php" method="post">
<center><h1>PHP-OPEN SOURCE ENVIRONMENT</h1></center>
<center><b>Firstname:</b><input type="text" name="firstname"
/><br><br>
<b>Lastname:</b><input type="text" name="lastname"
/><br><br>
<b>Age:</b><input type="text" name="age" /><br><br>
<input type="submit" /></center>
</form>
</body>
</html>
Insert.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<h1>1 record
added"; mysql_close($con)
?>
Output:
PROGRAM 11:
Program using PHP database functions

<?PHP

$user_name = "root"; $password = "";


$database = "addressbook"; $server = "127.0.0.1";

mysql_connect($server, $user_name, $password); print"Connection to the


Server opened";

?>
$db_found = mysql_select_db($database); if ($db_found) {
print "Database Found";
}

else {
print "Database NOT Found";

<?PHP

$user_name = "root"; $password = "";

$database = "addressbook"; $server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);


$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {
print "Database Found "; mysql_close($db_handle);
}

else {
print "Database NOT Found ";

?>
Output:

Thus the program using PHP database functionsexecuted


successfully.
PROGRAM 11:

Write a web application that functions as a simple hand calculator, but also keeps
a "paper trail" of all your previous work

Program code:

Html code:

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
<meta charset="utf-8">
<title>Simple Calculator using HTML, CSS and JavaScript</title>
<link rel="stylesheet" href="styles.css">
</head>

<body>

<table class="calculator" >


<tr>
<td colspan="3"> <input class="display-box" type="text" id="result" disabled />
</td>

<!-- clearScreen() function clears all the values -->


<td> <input type="button" value="C" onclick="clearScreen()" id="btn" /> </td>
</tr>
<tr>
<!-- display() function displays the value of clicked button -->
<td> <input type="button" value="1" onclick="display('1')" /> </td>
<td> <input type="button" value="2" onclick="display('2')" /> </td>
<td> <input type="button" value="3" onclick="display('3')" /> </td>
<td> <input type="button" value="/" onclick="display('/')" /> </td>
</tr>
<tr>
<td> <input type="button" value="4" onclick="display(4 ' ')" /> </td>
<td> <input type="button" value="5" onclick="display(5 ' ')" /> </td>
<td> <input type="button" value="6" onclick="display('6')" /> </td>
<td> <input type="button" value="-" onclick="display('-')" /> </td>
</tr>
<tr>
<td> <input type="button" value="7" onclick="display(7 ' ')" /> </td>
<td> <input type="button" value="8" onclick="display(8 ' ')" /> </td>
<td> <input type="button" value="9" onclick="display('9')" /> </td>
<td> <input type="button" value="+" onclick="display('+')" /> </td>
</tr>
<tr>
<td> <input type="button" value="." onclick="display('.')" /> </td>
<td> <input type="button" value="0" onclick="display('0')" /> </td>

<!-- calculate() function evaluates the mathematical expression -->


<td> <input type="button" value="=" onclick="calculate()" id="btn" /> </td>
<td> <input type="button" value="*" onclick="display('*')" /> </td>
</tr>
</table>

<script type="text/javascript" src="script.js"></script>

</body>

</html>

CSS code:
@import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');
.calculator {
padding: 10px;
border-radius: 1em;
height: 380px;
width: 400px;
margin: auto;
background-color: #191b28;
box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px;
}
.display-box {
font-family: 'Orbitron', sans-serif;
background-color:
#dcdbe1; border: solid
black 0.5px;
color: black;
border-radius: 5px;
width: 100%;
height: 65%;
}
#btn {
background-color: #fb0066;
}
input[type=button] {
font-family: 'Orbitron', sans-serif;
background-color: #64278f;
color: white;
border: solid black 0.5px;
width: 100%;
border-radius: 5px;
height: 70%;
outline: none;
}
input:active[type=button] {
background: #e5e5e5;
-webkit-box-shadow: inset 0px 0px 5px #c1c1c1;
-moz-box-shadow: inset 0px 0px 5px #c1c1c1;
box-shadow: inset 0px 0px 5px #c1c1c1;
}
JAVASCRIPT code:
function clearScreen() {
document.getElementById("result").value = "";
}

// This function display


values function
display(value) {
document.getElementById("result").value += value;
}

// This function evaluates the expression and returns result


function calculate() {
var p = document.getElementById("result").value;
var q = eval(p);
document.getElementById("result").value = q;
}
output:
PROGRAM 12:
Install Tomcat and use JSP and link it with any of the assignments above
Steps of Installation:
1 . Install Java.
2 . Install Apache Tomcat. At the time of installation, it will by-
default recognize JRE path. (under installed java location directory)

3 . Now Go-To: Start

Programs APACHE TOMCAT

MONITOR TOMCAT

4 . An icon will appear on the taskbar, this icon will


automatically appear after following above
5 . Click on that icon and START TOMCAT, you can see
the following dialog box:

6 . Now open Mozilla Firefox(or any other browser)

7 . Type http://localhost:8080/ on address bar and press


enter.The same can be seen here:

8 . It will show tomcat, as shown in above window. (if not, then try
again, may be a problem in installation or you?e not following above
steps correctly

9 . Now, go to: C:drive Programs Files

Apache Software Foundation tomcat

web-apps

(or navigate where you have installed APACHE TOMCAT)

10 . Open web-apps and ?opy your projector ?ake new folder which
you want to run in JSP. Example: amit2012PROJECT Now, goback :

Tomcat Root

Copy Web-inf from root

Paste this ?eb-infin your project folder i.e. amit2012PROJECT

11 . Create a text file and name it as first.jsp, use the code shownbelow:
<html>

<head>

<title>blog post:ApacheTomcatServer</title>
</head>

<body>

<%-- START --%>

<%

out.println("UserName = amit2012, "); out.println("Running first program in JSP.");


%>

<%-- END --%>

</body>

</html>

It includes HTML tags and encloses a JSP scriptlet which is a fragment of Java
code that is run when the user requests the page.

12 . Now for running your folder [ Eg. amit2012PROJECT asshown


above]

http://localhost:8080/foldername.extension in any WebBrowser i.e:


http://localhost:8080/amit2012PROJECT/first.jsp

The Project will run successfully, as shown below:

Now, you can successfully try running JSP with ApacheTomcatServer.


PROGRAM 13:
Reading and Writing the files using .Net

static void Main(string[] args)


{
// writing
using (StringWriter sw = new StringWriter())
{
sw.WriteLine("helloooooooooooooooooooo");
// Reading
using (StringReader sr = new StringReader(sw.ToString()))
{
string input = null;
while((input = sr.ReadLine())!=null)
{
Console.WriteLine(input);
}
}
}
}
Output:
Helloooooooooooooooooooooooooo
PROGRAM 14
Write a program to implement web service for calculator application

using System;

using System.Collections.Generic; using System.Linq;

using System.Web;

using System.Web.Services;

namespace calc

[WebService(Namespace = "mycalculatorexample.org")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

public class CalcWebService : System.Web.Services.WebService

[WebMethod]

public string calculate(string first, string second, char sign)

string result; switch (sign)


{

case '+':

{
result = (Convert.ToInt32(first) + Convert.ToInt32(second)).ToString();
break;

case '-':

result = (Convert.ToInt32(first) - Convert.ToInt32(second)).ToString();


break;

case '*':

result = (Convert.ToInt32(first) * Convert.ToInt32(second)).ToString();


break;

case '/':

result = (Convert.ToInt32(first) / Convert.ToInt32(second)).ToString();


break;

case '%':

{
result = (Convert.ToInt32(first) % Convert.ToInt32(second)).ToString(); break;

default:

result = "Invalid"; break;

}
return result;

}
Output:
Thus the implementation of web service for calculator
applicationexecuted successfully.
PROGRAM 15:

Implement RMI concept for building any remote method of your


choice.

1) create the remote interface


1. import java.rmi.*;
2. public interface Adder extends Remote{
3. public int add(int x,int y)throws
RemoteException; 4. }

2) Provide the implementation of the remote interface

1. import java.rmi.*;
2. import java.rmi.server.*;
3. public class AdderRemote extends UnicastRemoteObject implements Adder{
4. AdderRemote()throws RemoteException{
5. super();
6. }
7. public int add(int x,int y){return x+y;}
8. }

3) create the stub and skeleton objects using the rmic tool.

1. rmic AdderRemote

4) Start the registry service by the rmiregistry tool

rmiregistry 5000
5) Create and run the server application
public static java.rmi.Remote lookup(java.lang.String) throws
java.rmi.NotBoundException, java.net.MalformedURLException,
java.rmi.RemoteException;
Remote object by the name sonoo
1. import java.rmi.*;
2. import java.rmi.registry.*;
3. public class MyServer{
4. public static void main(String args[]){
5. try{
6. Adder stub=new AdderRemote();
7. Naming.rebind("rmi://localhost:5000/sonoo",stub);
8. }catch(Exception e){System.out.println(e);}
9. }
10.}

6) Create and run the client application


1. import java.rmi.*;
2. public class MyClient{
3. public static void main(String args[]){
4. try{
5. Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");
6. System.out.println(stub.add(34,4));
7. }catch(Exception e)
{} 8. }
9. }
Output:

You might also like