nerdexam
Cisco

300-435 · Question #19

Refer to the exhibit. The goal is to write a Python script to automatically send a message to an external messaging application when a rogue AP is detected on the network. The message should include…

The correct answer is D. bssids = return_val["alertData"]["bssids"] for value in bssids: send_to_application ("ALERT: detected a bssid on the network: "+value). To access the list of BSSIDs nested within 'alertData' in the return_val dictionary, correctly chain dictionary key access and then iterate through the list.

Operations

Question

Refer to the exhibit. The goal is to write a Python script to automatically send a message to an external messaging application when a rogue AP is detected on the network. The message should include the broadcast SSID that is in the alert. A function called "send_to_application" is created, and this is the declaration: send_to_application(message) The exhibit also shows the data that is received by the application and stored in the variable return_val. Which Python code completes the task?

Options

  • Abssids = return_val["bssids"] for number in range(return_val["countNode"]): send_to_application("ALERT: detected a bssid on the network: "+ return_val["alertData"][bssids][number])
  • Bbssids = return_val["bssids"] for value in bssids: send_to_application("ALERT: detected a bssid on the network: "+value)
  • Ccount = retutn_val["alertData"]["countNode"] bssids = return_val["alertData"][count]["bssids"] for value in bssids: send_to_application ("ALERT: detected a bssid on the network: "+value)
  • Dbssids = return_val["alertData"]["bssids"] for value in bssids: send_to_application ("ALERT: detected a bssid on the network: "+value)

How the community answered

(17 responses)
  • A
    12% (2)
  • C
    6% (1)
  • D
    82% (14)

Why each option

To access the list of BSSIDs nested within 'alertData' in the `return_val` dictionary, correctly chain dictionary key access and then iterate through the list.

Abssids = return_val["bssids"] for number in range(return_val["countNode"]): send_to_application("ALERT: detected a bssid on the network: "+ return_val["alertData"][bssids][number])

This choice incorrectly tries to access `bssids` directly from `return_val` instead of `return_val["alertData"]`, and the indexing `return_val["alertData"][bssids][number]` is also incorrect for iterating the list.

Bbssids = return_val["bssids"] for value in bssids: send_to_application("ALERT: detected a bssid on the network: "+value)

This choice incorrectly accesses `bssids` directly from `return_val`, missing the "alertData" nesting, which would result in a KeyError.

Ccount = retutn_val["alertData"]["countNode"] bssids = return_val["alertData"][count]["bssids"] for value in bssids: send_to_application ("ALERT: detected a bssid on the network: "+value)

This choice contains a typo (`retutn_val`), and `return_val["alertData"][count]["bssids"]` attempts to use the `count` variable as a key, which is incorrect for accessing the `bssids` list.

Dbssids = return_val["alertData"]["bssids"] for value in bssids: send_to_application ("ALERT: detected a bssid on the network: "+value)Correct

The BSSIDs list is nested under `alertData` and then `bssids`, so `return_val["alertData"]["bssids"]` correctly accesses the list of BSSIDs. The `for value in bssids:` loop then iterates through each SSID in the list and constructs the alert message for the `send_to_application` function.

Concept tested: Python dictionary nesting and iteration

Source: https://docs.python.org/3/tutorial/datastructures.html#dictionaries

Topics

#Python scripting#JSON parsing#Network event handling

Community Discussion

No community discussion yet for this question.

Full 300-435 Practice