0
0
Computer Networksknowledge~30 mins

Private vs public IP addresses in Computer Networks - Hands-On Comparison

Choose your learning style9 modes available
Understanding Private vs Public IP Addresses
📖 Scenario: You are setting up a small office network and need to understand how devices inside your office communicate with each other and with the internet.
🎯 Goal: Build a simple data structure that lists devices with their IP addresses, identify which IPs are private or public, and mark them accordingly.
📋 What You'll Learn
Create a dictionary with device names as keys and their IP addresses as values.
Add a list of private IP address ranges to check against.
Write logic to determine if each device's IP address is private or public.
Add a final dictionary that shows each device with its IP and whether it is private or public.
💡 Why This Matters
🌍 Real World
Understanding private vs public IP addresses helps in setting up secure home or office networks and managing internet access.
💼 Career
Network administrators and IT support staff need to know how to identify and configure private and public IP addresses for devices.
Progress0 / 4 steps
1
Create the devices dictionary with IP addresses
Create a dictionary called devices with these exact entries: 'Laptop': '192.168.1.10', 'Printer': '10.0.0.5', 'WebServer': '172.16.0.1', 'PublicSite': '8.8.8.8'.
Computer Networks
Need a hint?

Use a Python dictionary with device names as keys and IP addresses as string values.

2
Add the private IP ranges list
Create a list called private_ranges containing these exact strings: '192.168.', '10.', and '172.16.'.
Computer Networks
Need a hint?

Use a list of strings representing the start of private IP address ranges.

3
Determine if each IP is private or public
Create a dictionary called ip_types that uses a for loop with variables device and ip to iterate over devices.items(). For each IP, check if it starts with any prefix in private_ranges. If yes, set the value to 'Private', otherwise 'Public'.
Computer Networks
Need a hint?

Use a for loop and the startswith() method with any() to check prefixes.

4
Combine devices, IPs, and types into a final dictionary
Create a dictionary called device_info using a dictionary comprehension that iterates over devices.items(). Each key is the device name, and the value is another dictionary with keys 'IP' and 'Type' set to the device's IP and its type from ip_types.
Computer Networks
Need a hint?

Use a dictionary comprehension to combine IP and type info for each device.