You are on page 1of 13

Department of Electronics and Communication

Engineering
Laboratory Manual

Name of the course: Computer Networks


Course code: 15CS2208

Course Coordinator: Mr. Sreevardhan Cheerla


Course instructers: Dr. V. S. V. Prabhakar, Dr. Ch. Raghava Prasad,
Mr. Shameem, Mr. Raghuveera, Mrs. Nagendram,

Mrs. Durga Indira, Mrs. Sony.K, Ms.Cynthia,

Mr. Ramesh Kumar


List of Experiments:-
1. Implement a program using Python to find (a) IP Address (b) URL (c) Port
Numbers/Names

2. Implement a program using Python for the data link layer farming methods
such as (a) Byte Stuffing (b) Bit Stuffing (c) Character Count

3. Program to retrieve the IP address and network name by using DNS Server

4. Program to communicate with any network server to get the reply for the
given message.

5. (a) Program to calculate the parity bit for the given data word
(b) Program to calculate the checksum for the given data word using generator
Polynomial.

6. Program to implement the Client server model using TCP protocol

7. Program to implement the client server model using UDP protocol

8. Program to find out the shortest path using Dijsktra’s Algorithm

9. Program to classify the type of networks for the given IP address

10. Program to implement the subnetting and masking.


EXPERIMENT-1
Implement a program using Python to find
(a)IP Address (b) URL (c) Port Numbers/Names
(a)IP Address
Aim: To implement a program using Python to find out the IP Address.
Description:
An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g.,
computer, printer) participating in a computer network that uses the Internet Protocol for
communication. An IP address serves two principal functions: host or network interface
identification and location addressing. Its role has been characterized as follows: "A name
indicates what we seek. An address indicates where it is. A route indicates how to get there.
An IP is a 32-bit number comprised of a host number and a network prefix, both of which are
used to uniquely identify each node within a network.
To make these addresses more readable, they are broken up into 4 bytes, or octets, where any 2
bytes are separated by a period. This is commonly referred to as dotted decimal notation.
The first part of an Internet address identifies the network on which the host resides, while the
second part identifies the particular host on the given network. This creates the two-level
addressing hierarchy.
All hosts on a given network share the same network prefix but must have a unique host number.
Similarly, any two hosts on different networks must have different network prefixes but may have
the same host number.
Here is a simple example of an IP address: 192.168.1.1
Source Code:
import socket
print socket.gethostbyname(‘www.kluniversity.in’)
Output:
49.156.157.71
(b)URL
Aim: To implement a program using Python to find out the URL.
Description:
URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource
on the Internet. A URL has two main components:
Protocol identifier: For the URL http://example.com, the protocol identifier is http.
Resource name: For the URL http://example.com, the resource name is example.com.
Note that the protocol identifier and the resource name are separated by a colon and two forward
slashes. The protocol identifier indicates the name of the protocol to be used to fetch the resource.
The example uses the Hypertext Transfer Protocol (HTTP), which is typically used to serve up
hypertext documents. HTTP is just one of many different protocols used to access different types
of resources on the net. Other protocols include File Transfer Protocol (FTP), Gopher, File, and
News.
The resource name is the complete address to the resource. The format of the resource name
depends entirely on the protocol used, but for many protocols, including HTTP, the resource
name contains one or more of the following components:
Host Name
The name of the machine on which the resource lives.
Filename
The pathname to the file on the machine.
Port Number
The port number to which to connect (typically optional).
Source Code:
import socket
print socket.gethostbyaddress(49.156.157.71)
Output:
www.kluniversity.in
(c)Port Numbers/Names
Aim: To implement a program using Python to find out the Port Numbers/Names.
Description:
In the internet protocol suite, a port is an endpoint of communication in an operating system.
While the term is also used for hardware devices, in software it is a logical construct that
identifies a specific process or a type of network service. A port is always associated with an IP
address of a host and the protocol type of the communication, and thus completes the destination
or origination address of a communication session. A port is identified for each address and
protocol by a 16-bit number, commonly known as the port number.
Specific port numbers are often used to identify specific services. Of the thousands of enumerated
ports, 1024 well-known port numbers are reserved by convention to identify specific service
types on a host. In the client–server model of application architecture, the ports that network
clients connect to for service initiation provide a multiplexing service. After initial
communication binds to the well-known port number, this port is freed by switching each
instance of service requests to a dedicated, connection-specific port number, so that additional
clients can be serviced. The protocols that primarily use ports are the transport layer protocols,
such as the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP).
Ports were unnecessary on direct point-to-point links when the computers at each end could only
run one program at a time. Ports became necessary after computers became capable of executing
more than one program at a time and were connected to modern packet-switched networks.
Source Code:
print(‘service by port is’,socket.getservbyport(80,’tcp’))
Output:
service by port is http
Source Code:
print(‘service by port is’,socket.getservbyport(25,’tcp’))
Output:
service by port is smtp
Output:
www.kluniversity.in
(c)Port Numbers/Names
Aim: To implement a program using Python to find out the Port Numbers/Names.
Description:
In the internet protocol suite, a port is an endpoint of communication in an operating system.
While the term is also used for hardware devices, in software it is a logical construct that
identifies a specific process or a type of network service. A port is always associated with an IP
address of a host and the protocol type of the communication, and thus completes the destination
or origination address of a communication session. A port is identified for each address and
protocol by a 16-bit number, commonly known as the port number.
Specific port numbers are often used to identify specific services. Of the thousands of enumerated
ports, 1024 well-known port numbers are reserved by convention to identify specific service
types on a host. In the client–server model of application architecture, the ports that network
clients connect to for service initiation provide a multiplexing service. After initial
communication binds to the well-known port number, this port is freed by switching each
instance of service requests to a dedicated, connection-specific port number, so that additional
clients can be serviced. The protocols that primarily use ports are the transport layer protocols,
such as the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP).
Ports were unnecessary on direct point-to-point links when the computers at each end could only
run one program at a time. Ports became necessary after computers became capable of executing
more than one program at a time and were connected to modern packet-switched networks.
Source Code:
print(‘service by port is’,socket.getservbyport(80,’tcp’))
Output:
service by port is http
Source Code:
print(‘service by port is’,socket.getservbyport(25,’tcp’))
Output:
service by port is smtp
a. Byte Or Character Stuffing

AIM: Implementation of data link framing methods for character stuffing in a frame.
LOGIC:
In a character data frame if a DLE is encountered between the data it is doubled and transmitted
at the receiver side it is de stuffed and original data is obtained.
Description:
In the second method, each frame starts with the ASCII character sequence DLE STX and ends
with the sequence DLE ETX.(where DLE is Data Link Escape, STX is Start of TeXt and ETX is
End of TeXt.) This method overcomes the drawbacks of the character count method. If the
destination ever loses synchronization, it only has to look for DLE STX and DLE ETX
characters. If however, binary data is being transmitted then there exists a possibility of the
characters DLE STX and DLE ETX occurring in the data. Since this can interfere with the
framing, a technique called character stuffing is used. The sender's data link layer inserts an
ASCII DLE character just before the DLE character in the data. The receiver's data link layer
removes this DLE before this data is given to the network layer. However character stuffing is
closely associated with 8-bit characters and this is a major hurdle in transmitting arbitrary sized
characters.
Character Stuffing
Souce Code:
while(True):
s=raw_input('enter ur payload: ').split();
a='flag'
b=''
for x in s:
if x==a:
x='esc '+a
if x=='esc':
x='esc'+' '+x
b=' '+b+' '+x
print b
Output:
enter ur payload: cn flag
cn esc flag
b. Bit Stuffing

AIM: Implementation of the data link framing methods for the bit stuffing in a frame.
LOGIC: Stuffing a 0 bit in a data frame in order to differentiate the header, trailer and data.
Description:
The third method allows data frames to contain an arbitrary number of bits and allows character
codes with an arbitrary number of bits per character. At the start and end of each frame is a flag
byte consisting of the special bit pattern 01111110.Whenever the sender's data link layer
encounters five consecutive 1s in the data, it automatically stuffs a zero bit into the outgoing bit
stream. This technique is called bit stuffing. When the receiver sees five consecutive 1s in the
incoming data stream, followed by a zero bit, it automatically destuffs the 0 bit. The boundary
between two frames can be determined by locating the flag pattern.

Physical layer coding violations :


The final framing method is physical layer coding violations and is applicable to networks in
which the encoding on the physical medium contains some redundancy. In such cases normally, a
1 bit is a high-low pair and a 0 bit is a low-high pair. The combinations of low-low and high-high
which are not used for data may be used for marking frame boundaries.
Source code:
while(True):
s=raw_input('enter ur payload:\n')
c=0;si=''
for x in s:
if x=='0':
c=0
if x=='1':
c+=1
if c==5:
x='10';c=0
si+=x
print si
Output:
enter ur payload:
111110
1111110
b. Bit Stuffing

AIM: Implementation of the data link framing methods for the bit stuffing in a frame.
LOGIC: Stuffing a 0 bit in a data frame in order to differentiate the header, trailer and data.
Description:
The third method allows data frames to contain an arbitrary number of bits and allows character
codes with an arbitrary number of bits per character. At the start and end of each frame is a flag
byte consisting of the special bit pattern 01111110.Whenever the sender's data link layer
encounters five consecutive 1s in the data, it automatically stuffs a zero bit into the outgoing bit
stream. This technique is called bit stuffing. When the receiver sees five consecutive 1s in the
incoming data stream, followed by a zero bit, it automatically destuffs the 0 bit. The boundary
between two frames can be determined by locating the flag pattern.

Physical layer coding violations :


The final framing method is physical layer coding violations and is applicable to networks in
which the encoding on the physical medium contains some redundancy. In such cases normally, a
1 bit is a high-low pair and a 0 bit is a low-high pair. The combinations of low-low and high-high
which are not used for data may be used for marking frame boundaries.
EXPERIMENT -3
AIM: Program to retrieve the IP address and network name by using DNS Server.
Description:
Every computer connected to the Internet has a unique identity. You can refer to any Internet-
connected machine in either of two ways:
• by its IP address (a four-part number string such as "18.72.0.3"), in which the first part(s)
identify the specific network to which the machine is connected (e.g., "18" refers to the main MIT
network).
• by its host name (a text string such as "bitsy.mit.edu") which consists of the machine name
(e.g., "bitsy") and the domain name (e.g., "mit.edu" refers to the main MIT network).

The Internet Domain Name Service (DNS) can translate host names into equivalent IP addresses
and vice versa, as needed by various Internet programs.
Domain Name Service (DNS)
On the Internet, many communications programs deal only with IP addresses, yet allow their
users to specify machines in terms of their host names (or alias host names). Or a program which
already knows the IP address must determine the domain name for the network to which the
machine is connected. Such programs must somehow convert the host names into IP addresses
(or vice versa) behind the scenes. How do they achieve this translation between IP addresses and
host names?
The mapping of host names to IP addresses is handled through a service called Domain Name
Service (DNS). Rather than require individual machines, applications, or users to keep up with
the constant changes in host names and IP addresses, a series of special DNS servers across the
world (known as "name servers") keep track of the name/address information for all the
computers on the Internet. Applications that need to determine an IP address from a host name (or
vice versa) contact the local "name server" to supply this information.
Program:
import socket
ip = socket.gethostbyname('Localhost')
ip1 = socket.gethostbyname('www.google.com')
ip2 = socket.gethostbyaddr('www.kluniversity.in')
print(ip)
print(ip1)
print(ip2)

Expected Output:
127.0.0.1
172.217.26.196
('KLCEBLADE4', [], ['49.156.157.71

You might also like