Protocols, IP, DNS & Web
What is a protocol?
A protocol is a set of rules that devices follow to communicate – the format of data, how to start and end, and how to handle errors. Like grammar for a language, both sides must follow the same protocol.
Common protocols
| Protocol | Full form | Used for |
|---|---|---|
| HTTP / HTTPS | HyperText Transfer Protocol (Secure) | Web pages |
| FTP | File Transfer Protocol | Uploading / downloading files |
| SMTP | Simple Mail Transfer Protocol | Sending email |
| POP3 / IMAP | Post Office Protocol 3 / Internet Message Access Protocol | Receiving email |
| TCP/IP | Transmission Control Protocol / Internet Protocol | Basic Internet communication |
| PPP | Point-to-Point Protocol | Direct link between two devices (dial-up) |
| TELNET | Teletype Network | Remote login (text, not secure) |
| VoIP | Voice over Internet Protocol | Voice calls over the Internet (WhatsApp call) |
TCP/IP
TCP breaks a message into packets, numbers them, checks for errors and reassembles them at the destination. IP puts the source and destination addresses on each packet and routes it across networks.
IP address
An IP address is a unique logical address for every device on a network. IPv4 uses 32 bits written as four numbers 0–255 (192.168.1.10). Because IPv4 addresses are running out, IPv6 uses 128 bits (2001:db8::1).
def valid_ipv4(ip):
parts = ip.split('.')
if len(parts) != 4:
return False
for p in parts:
if not p.isdigit() or not 0 <= int(p) <= 255:
return False
return True
for ip in ['192.168.1.10', '256.10.1.1', '10.0.0', '8.8.8.8']:
print(ip.ljust(14), valid_ipv4(ip))ip = '192.168.1.10'
print('Binary:', '.'.join(format(int(x), '08b') for x in ip.split('.')))
print('IPv4 has', 2 ** 32, 'addresses; IPv6 has 2**128')MAC vs IP address
MAC address
- Physical address burned into the NIC
- 48 bits, e.g. 00:1A:2B:3C:4D:5E
- Never changes
- Used inside a LAN (by switches)
IP address
- Logical address given by the network
- IPv4 32 bits / IPv6 128 bits
- Can change when you change network
- Used across networks (by routers)
Domain Name System (DNS)
People remember names, computers use numbers. DNS servers convert a domain name into its IP address. Domains have levels: .in, .com, .org, .gov.in are top-level domains.
URL and its parts
A URL (Uniform Resource Locator) is the complete address of a resource on the web.
from urllib.parse import urlparse
u = urlparse('https://www.codingeasily.in:443/tutorial/class-12-cs/stack?lang=hi#push')
print('Protocol :', u.scheme)
print('Domain :', u.hostname)
print('Port :', u.port)
print('Path :', u.path)
print('Query :', u.query)
print('Fragment :', u.fragment)WWW, websites and web servers
- WWW – the system of linked web pages on the Internet, invented by Tim Berners-Lee (1990). The Internet is the network; the web is one service on it.
- Web page – a document written in HTML; website – a group of related pages under one domain.
- Static pages show the same content to everyone; dynamic pages are generated by programs (PHP, Python) and change per user.
- Web server – a computer/software (Apache, Nginx) that stores websites and sends pages to browsers.
- Web hosting – renting space on a web server so a site is online 24×7.
Browsers, cookies and plug-ins
A web browser (Chrome, Firefox, Edge, Safari) requests and displays web pages. Cookies are small text files a website saves in your browser to remember login, language or cart. Add-ons / plug-ins extend what a browser can do.
