
Prerequisites:
You will need to install Python 3 locally on your Laptop.
Debian/Ubuntu/Mint: In the terminal, run
sudo apt-get install python3
After Installation make sure python3 is installed successfully, by checking the version
python3 --version

Nmap Network testing tooling
You’ll also need to install ncat, which is part of the Nmap network testing toolkit. We’ll be using ncat to investigate how web servers and browsers talk to each other.
Debian/Ubuntu/Mint: In the terminal, run
sudo apt-get install nmap
sudo apt-get install ncat
To check whether ncat is installed and working, open up two terminals. In one of them, run
ncat -l 9999
in the other,
ncat localhost 9999
Then type something into each terminal and press Enter. You should see the message on the opposite terminal.


What is a Server
A server is just a program that accepts connections from other programs on the network.
When you start a server program, it waits for clients to connect to it. server waiting for your web browser to ask it for a page. Then when a connection comes in, the server runs a piece of code like calling a function to handle each incoming connection. A connection in this sense is like a phone call, it’s a channel through which the client and server can talk to each other. Web clients send requests over these connections, and servers send responses back.
a web server provides support for HTTP (Hypertext Transfer Protocol). As its name implies, HTTP specifies how to transfer hypertext (linked web documents) between two computers.
Running the first web server
So, let’s get started with the demo web server:
- Open up a terminal.
cdinto a directory that has some files in it ( text files, HTML files, or images ).- Run
python3 -m http.server 8000in your terminal.

Look! The server tells me that it’s serving HTTP on port 8000.
When you start up the demo server, it will print a message telling you that it’s serving HTTP. Leave it running, and leave the terminal open. Now try accessing http://localhost:8000/ from your browser. You should see something like this

In my web browser, I see the demo server showing the same files that are in my Documents directory.
And that’s the Python demo web server, running on your own computer. It serves up files on your local disk so you can look at them in your browser.
When you put localhost:8000 in your browser, your browser sends an HTTP request to the Python program you’re running. That program responds with a piece of data, which your browser presents to you.
Look in the terminal where you ran the demo server. You’ll see a server log with an entry for each request your browser sent.

Hostnames
HTTPS URI includes the hostname of the web server, like www.google.com or www.cheeseboardcollective.coop
A hostname in a URI can also be an IP address: for example, if you put http://216.58.194.174/ in your browser, you’ll end up at Google.
The Internet tells computers apart by their IP addresses; every piece of network traffic on the Internet is labeled with the IP addresses of the sending and receiving computers. In order to connect to a web server such as www.google.com, a client needs to translate the hostname into an IP address. Your operating system’s network configuration uses the Domain Name Service (DNS) a set of servers maintained by Internet Service Providers (ISPs) and other network users to look up hostnames and get back IP addresses.
In the terminal, you can use the host program to look up hostnames in DNS:

The output shows both an IPv4 address and an IPv6 address.
Another similar command called nslookup
This command also displays the IP address for the hostname you give it; but it also shows the IP address of the DNS server that’s giving it the answer

Send a Request
use ncat to connect to the demo server and send it an HTTP request.
Use ncat 127.0.0.1 8000 to connect your terminal to the demo server.
Then type these two lines:
GET / HTTP/1.1
Host: localhost
After the second line, press Enter twice. As soon as you do, the response from the server will be displayed a lot of text on your terminal.

Everything after the line Host: localhost is part of the server’s response.
Be a web server!
Use ncat -l 9999 to listen on port 9999. Connect to it with your web browser at http://localhost:9999/.
and see the response from the server in your terminal

Next, send an HTTP response to your browser by typing it into the terminal, right under where you see the headers the browser sent to you.
HTTP/1.1 307 Temporary Redirect
Location: https://www.eff.org/
At the end, press Enter twice to send a blank line to mark the end of headers.

Now again run http://localhost:9999/ on your browser you will see a webpage like.

So, that is it for this blog. Hope you will do it yourself. Do let me know your feedback in the comment section. I will really appreciate it.