Introduction to common network protocols
when computers communicate over a network, they follow specific rules called protocols. each protocol is designed for a particular purpose, such as loading websites, transferring files, or remotely controlling another computer.
think of a protocol as a language with strict rules. if both sides follow the same rules, communication works correctly.
Below is a beginner-friendly explanation of some of the most common protocols used on the internet.
1. https (hypertext transfer protocol secure)
https is the secure version of http. it is used for loading websites securely.
when you visit a website like:
your browser and the web server communicate using https.
how https works:
https uses:
why https is important:
example using python to make an https request:
import requests
response = requests.get("https://example.com")
print(response.status_code)
print(response.text[:200])
2. ftp (file transfer protocol)
ftp is used to transfer files between computers over a network.
it typically uses:
ftp is not secure by default because it sends data in plain text.
common uses:
secure alternatives:
example ftp connection in python:
from ftplib import FTP
ftp = FTP("ftp.example.com")
ftp.login(user="username", passwd="password")
ftp.retrlines("LIST")
ftp.quit()
3. ssh (secure shell)
ssh allows you to remotely access and control another computer securely.
it usually runs on port 22.
what ssh does:
example use case:
you connect from your laptop to a remote linux server:
ssh user@server_ip
behind the scenes, ssh:
ssh uses strong encryption to prevent eavesdropping.
example using python (paramiko library):
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("example.com", username="user", password="password")
stdin, stdout, stderr = ssh.exec_command("ls")
print(stdout.read().decode())
ssh.close()
4. smtp
smtp is used to send emails between mail servers.
it usually runs on:
smtp handles sending emails, not receiving them.
example sending email with python:
import smtplib
server = smtplib.SMTP("smtp.example.com", 587)
server.starttls()
server.login("user@example.com", "password")
message = "Subject: Test\n\nThis is a test email."
server.sendmail("user@example.com", "recipient@example.com", message)
server.quit()
5. pop3 and imap
these protocols are used to receive emails.
pop3 (post office protocol version 3):
imap (internet message access protocol):
imap is more modern and commonly used today.
6. dns (domain name system)
dns translates domain names into ip addresses.
example:
when you type:
google.com
dns translates it into something like:
142.250.190.14
dns usually uses:
without dns, you would have to remember numeric ip addresses for every website.
7. dhcp (dynamic host configuration protocol)
dhcp automatically assigns ip addresses to devices on a network.
when you connect to wifi:
dhcp usually uses:
summary of common protocols
https:
ftp:
ssh:
smtp:
pop3:
imap:
dns:
dhcp:
How these protocols work together
when you open a website:
each protocol has a specific role, and together they make the internet function smoothly.
# =========================
# https request example
# =========================
import requests
def https_example():
response = requests.get("https://example.com")
print(response.status_code)
print(response.text[:200])
# =========================
# ftp example
# =========================
from ftplib import FTP
def ftp_example():
ftp = FTP("ftp.example.com")
ftp.login(user="username", passwd="password")
ftp.retrlines("LIST")
ftp.quit()
# =========================
# ssh example
# =========================
import paramiko
def ssh_example():
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("example.com", username="user", password="password")
stdin, stdout, stderr = ssh.exec_command("ls")
print(stdout.read().decode())
ssh.close()
# =========================
# smtp example
# =========================
import smtplib
def smtp_example():
server = smtplib.SMTP("smtp.example.com", 587)
server.starttls()
server.login("user@example.com", "password")
message = "Subject: Test\n\nThis is a test email."
server.sendmail("user@example.com", "recipient@example.com", message)
server.quit()
# choose which function to run manually
# https_example()
# ftp_example()
# ssh_example()
# smtp_example()