0
0
Intro to Computingfundamentals~10 mins

IP addresses (IPv4, IPv6) in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the version of the IP address.

Intro to Computing
ip_version = [1].version
print(f"IP version: {ip_version}")
Drag options to blanks, or click blank then click option'
Aip.version()
Bipaddress.IPv4Address('192.168.1.1')
Cip.version
Dip.version_number
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses like a method call (ip.version())
Trying to access a non-existent attribute like ip.version_number
2fill in blank
medium

Complete the code to create an IPv4 address object from a string.

Intro to Computing
import ipaddress
ip = ipaddress.[1]('10.0.0.1')
print(ip)
Drag options to blanks, or click blank then click option'
AIPv4Address
BIPv6Address
CIPAddress
DIPNetwork
Attempts:
3 left
💡 Hint
Common Mistakes
Using IPv6Address for an IPv4 string
Using IPAddress which does not exist in the module
3fill in blank
hard

Fix the error in the code to check if an IP address is private.

Intro to Computing
import ipaddress
ip = ipaddress.IPv4Address('172.16.0.1')
print(ip.[1])
Drag options to blanks, or click blank then click option'
Aprivate
Bis_private
CisPrivate
Dprivate_ip
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase like isPrivate
Using 'private' without 'is_' prefix
4fill in blank
hard

Fill both blanks to create a dictionary mapping IP strings to their versions for a list of IPs.

Intro to Computing
import ipaddress
ips = ['192.168.1.1', '2001:db8::1']
result = {ip: ipaddress.[1](ip).[2] for ip in ips}
print(result)
Drag options to blanks, or click blank then click option'
AIPv4Address
Bversion
CIPv6Address
Dis_private
Attempts:
3 left
💡 Hint
Common Mistakes
Using IPv6Address for all IPs causes errors for IPv4
Using is_private instead of version for the second blank
5fill in blank
hard

Fill all three blanks to create a dictionary of IPs with their version and private status.

Intro to Computing
import ipaddress
ips = ['10.0.0.1', '2001:db8::1']
result = {ip: {'version': ipaddress.[1](ip).[2], 'private': ipaddress.[3](ip).is_private} for ip in ips}
print(result)
Drag options to blanks, or click blank then click option'
Aip_address
Bversion
CIPv6Address
DIPv4Address
Attempts:
3 left
💡 Hint
Common Mistakes
Using IPv4Address or IPv6Address instead of ip_address() for mixed IPs
Using is_private as a method instead of an attribute