TCP/IP, IP addresses, and ports
corebeginnerTCP/IP is the layered set of protocols the internet runs on: IP delivers a packet to the right HOST using an IP address, and a port number then delivers it to the right PROCESS on that host. TCP is the layer on top that makes delivery reliable and ordered.
Think of it as
An IP address is a street address — it gets a letter to the right building. A port number is the apartment number on that letter — it gets the letter to the right resident inside the building. TCP is the postal service adding tracking, delivery confirmation, and reordering pages that arrived out of sequence, on top of an IP layer that only promises "best effort, no guarantees."
What we're doing: Validate an IP address and a subnet with the ipaddress module, and show that a service is really identified by an (IP, port) pair, not the IP alone.
- 3
- ip_address() parses and validates -- it raises ValueError on anything that is not a real IPv4/IPv6 address, rather than silently accepting a bad string.
- 5
- .is_private confirms 192.168.1.10 falls in a reserved private range (RFC 1918) -- not routable on the public internet directly.
- 8
- ip_network parses a whole CIDR block; num_addresses is computed from the prefix length (/24 = 2^(32-24) = 256).
IPv4Address True
IPv6Address 6
network: 192.168.1.0/24 num addresses: 256Why this works: ip_address() and ip_network() do real structural validation, not just string formatting -- they reject malformed addresses and compute real network math (address count from prefix length), which is what makes them safer than string-splitting an address by hand.
Treating an IP address alone as identifying a running service
Wrong
Better
What you see: A vague "the server is unreachable" report that turns out to mean only one specific port/service on that host is down, wasting time investigating the wrong process.
Why: A host can run many independent services simultaneously, one per port. Reachability, load, and failures are properties of a specific (IP, port) endpoint, not of the IP address alone -- diagnosing "the server" without naming the port skips the information that actually narrows down the problem.
- Application data — an HTTP request, a DNS query, ...
- TCP/UDP + port — e.g. destination port 443 — picks the process
- IP + IP address — e.g. destination 192.168.1.10 — picks the host
- Link layer — Ethernet/Wi-Fi frame — picks the device on this wire
The four layers a web request actually crosses
Together
Remember: An IP address routes to a HOST; a port routes to a PROCESS on that host; a service is really identified by the (IP, port) pair together, not by either alone.
See also: tcp vs udp · sockets · dns

