350-201 exam dumps

350-201 practice question 241 of 289

Cybersecurity Professional - Performing Cybersecurity Using Cisco Security Technologies. Professional level, Cisco. Free question with the correct answer and a full explanation.

350-201 Question 241

Select 4

You are tasked with analyzing a Python script used to automate the addition of IP addresses to a firewall rule using the Cisco Firepower Management Center (FMC) API. Below is a snippet of the script:

import requests

def add_ip_to_firewall(ip_address, api_url, token):
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {token}'
    }
    payload = {
        'ip': ip_address
    }
    response = requests.post(f'{api_url}/add_ip', headers=headers, json=payload)
    if response.status_code == 200:
        return "Success"
    else:
        return f"Error: {response.status_code}"

ip = "192.168.1.100"
api_endpoint = "https://fmc-server/api"
api_token = "abcd1234"
result = add_ip_to_firewall(ip, api_endpoint, api_token)
print(result)

After reviewing the script, which of the following statements are correct about its functionality?

  1. A

    The script uses an HTTP POST request to add an IP address to the firewall.

  2. B

    The 'Authorization' header is dynamically generated using the provided API token.

  3. C

    The script will fail if the API token is invalid or expired.

  4. D

    The script uses the GET method to retrieve the list of IP addresses from the firewall.

  5. E

    The API endpoint in the script is hardcoded and not dynamically derived.

Show answer and explanation

Correct answers: A, B, C, E

Explanation

The script demonstrates the use of Python and the requests library to interact with the Cisco FMC API. It uses an HTTP POST request to add an IP address to the firewall. The 'Authorization' header and the payload are dynamically generated based on the provided arguments, but the API endpoint is hardcoded. If the token is invalid or expired, the operation will fail, which aligns with how most APIs handle authentication.

  • A. Correct.

    Correct. The requests.post method is used, indicating an HTTP POST request is being made to the API.

  • B. Correct.

    Correct. The 'Authorization' header is constructed dynamically using the token provided as a function argument.

  • C. Correct.

    Correct. If the API token is invalid or expired, the request will fail, likely returning an error status code other than 200.

  • D. Incorrect.

    Incorrect. The script does not use the GET method; it explicitly uses POST to add an IP address.

  • E. Correct.

    Correct. The API endpoint is hardcoded in the variable api_endpoint and is not dynamically derived.

Timed practice exam

Take a 350-201 practice test under exam conditions

75 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam