Complete the code to import the mDNS library for device discovery.
import [1]
The zeroconf library is commonly used in Python for mDNS (multicast DNS) service discovery.
Complete the code to create a Zeroconf instance for mDNS service discovery.
from zeroconf import Zeroconf zeroconf = [1]()
The Zeroconf() class creates an instance to manage mDNS services.
Fix the error in the code to correctly browse for HTTP services over mDNS.
from zeroconf import ServiceBrowser, Zeroconf zeroconf = Zeroconf() browser = ServiceBrowser(zeroconf, [1], None)
The correct service type string for HTTP over TCP in mDNS is _http._tcp.local..
Fill both blanks to create a ServiceInfo object for advertising a printer service.
from zeroconf import ServiceInfo info = ServiceInfo( [1], "MyPrinter._ipp._tcp.local.", addresses=[[2]], port=631, properties={} )
The service type for IPP printers is "_ipp._tcp.local.". The address must be a byte string representing the IP, here b"\xc0\xa8\x01\x64" is 192.168.1.100.
Fill all three blanks to create a dictionary comprehension that maps device names to their IP addresses for devices with port above 8000.
devices = {
[1]: [2] for [3] in discovered_devices if [3]['port'] > 8000
}The comprehension iterates over discovered_devices as device, uses device['name'] as key and device['ip'] as value. device is the dictionary for each device.
