Bird
0
0

A network uses MAC address filtering to allow only devices from two manufacturers with OUIs 00:1A:2B and 00:1B:3C. Which Python code snippet correctly filters a list of MAC addresses named mac_list?

hard📝 Application Q9 of 15
Computer Networks - Physical and Data Link Layer
A network uses MAC address filtering to allow only devices from two manufacturers with OUIs 00:1A:2B and 00:1B:3C. Which Python code snippet correctly filters a list of MAC addresses named mac_list?
Afiltered = [mac for mac in mac_list if mac.endswith(('00:1A:2B', '00:1B:3C'))]
Bfiltered = [mac for mac in mac_list if mac.startswith(('00:1A:2B', '00:1B:3C'))]
Cfiltered = [mac for mac in mac_list if '00:1A:2B' in mac or '00:1B:3C' in mac]
Dfiltered = [mac for mac in mac_list if mac == '00:1A:2B' or mac == '00:1B:3C']
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering by OUI

    Filtering requires checking if MAC addresses start with either OUI string.
  2. Step 2: Analyze code options

    filtered = [mac for mac in mac_list if mac.startswith(('00:1A:2B', '00:1B:3C'))] uses startswith with a tuple, correctly filtering by OUI prefixes. filtered = [mac for mac in mac_list if mac.endswith(('00:1A:2B', '00:1B:3C'))] checks suffixes, which is incorrect. filtered = [mac for mac in mac_list if '00:1A:2B' in mac or '00:1B:3C' in mac] checks anywhere in string, which may cause false positives. filtered = [mac for mac in mac_list if mac == '00:1A:2B' or mac == '00:1B:3C'] checks exact match, which is too strict.
  3. Final Answer:

    filtered = [mac for mac in mac_list if mac.startswith(('00:1A:2B', '00:1B:3C'))] -> Option B
  4. Quick Check:

    Use startswith to filter by OUI prefixes [OK]
Quick Trick: Use startswith() with OUI tuple to filter MAC addresses [OK]
Common Mistakes:
MISTAKES
  • Using endswith instead of startswith
  • Checking substring anywhere in MAC
  • Comparing full MAC to OUI only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Computer Networks Quizzes