Complete the code to print the version of the IP address.
ip_version = [1].version print(f"IP version: {ip_version}")
The version attribute of an IP address object gives the IP version (4 or 6).
Complete the code to create an IPv4 address object from a string.
import ipaddress ip = ipaddress.[1]('10.0.0.1') print(ip)
To create an IPv4 address object, use IPv4Address from the ipaddress module.
Fix the error in the code to check if an IP address is private.
import ipaddress ip = ipaddress.IPv4Address('172.16.0.1') print(ip.[1])
The correct attribute to check if an IP is private is is_private.
Fill both blanks to create a dictionary mapping IP strings to their versions for a list of IPs.
import ipaddress ips = ['192.168.1.1', '2001:db8::1'] result = {ip: ipaddress.[1](ip).[2] for ip in ips} print(result)
Use IPv4Address for IPv4 addresses, but here we want to create an IP address object that works for both IPv4 and IPv6, so this code will fail for IPv6. The correct approach is to use ipaddress.ip_address() but since the task is to fill blanks, IPv4Address is the correct option for the first blank to match the code. The second blank is the version attribute to get the IP version.
Fill all three blanks to create a dictionary of IPs with their version and private status.
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)
The ipaddress.ip_address() function creates an IP address object for both IPv4 and IPv6. The version attribute gives the IP version. To check if the IP is private, use is_private on the same IP address object created by ip_address().