Lesson 2 of 5
IP Addresses and DNS
Discover the global address book that turns human names into numerical internet coordinates.
Learn it
Computers do not understand names like codequest.co.uk. Instead, they rely on numbers called IP addresses, which work just like postal postcodes for machines.
Because memorising strings of numbers is tough for humans, the internet uses the Domain Name System (DNS). It acts like a giant, super-fast contacts list that translates readable names into numerical addresses in a fraction of a second.
Key terms
- IP Address
- A unique numerical identifier assigned to every device connected to an IP network.
- DNS (Domain Name System)
- The decentralised naming system that translates human-readable domain names into IP addresses.
- A Record
- A specific DNS record type that maps a domain name directly to an IPv4 address.
- Resolver
- A local DNS server, often run by your ISP, that fetches DNS records on behalf of a client.
Tracing a Domain Lookup
Use command-line tools to discover the IP address behind common web domains.
- 1Open Terminal or Command Prompt: Launch your system terminal (macOS/Linux) or Command Prompt (Windows).
- 2Run nslookup: Type 'nslookup example.com' and press Enter to query your default DNS server.
- 3Inspect the Response: Observe the Non-authoritative answer providing an IPv4 address (like 93.184.216.34).
- 4Test an IPv6 Lookup: Try 'nslookup -type=AAAA google.com' to observe 128-bit hexadecimal addresses.
Resolving an IP in Python
pythonimport socket
domain = "example.com"
ip_address = socket.gethostbyname(domain)
print(f"Domain: {domain}")
print(f"Resolved IPv4 Address: {ip_address}")Python's built-in socket library contacts your operating system's DNS resolver to fetch the matching IP address for a host name.
Try it
Match each DNS/IP component with its correct function:
Challenge
Write a short Python script that takes a list of three domain names and prints each domain with its resolved IP address.
Pick whichever way suits you — every mode earns the same bonus XP.
Write at least 40 more characters to submit.
Mark your own work
Guided walkthrough — 0/5 clues revealed
- Clue 1 locked — reveal it only if you get stuck.
- Clue 2 locked — reveal it only if you get stuck.
- Clue 3 locked — reveal it only if you get stuck.
- Clue 4 locked — reveal it only if you get stuck.
- Clue 5 locked — reveal it only if you get stuck.
Each clue costs 3 XP (never below 15 XP). You'd earn 30 XP right now.
Extension: Add exception handling with try/except socket.gaierror to gracefully catch invalid or non-existent domains.