300-435 · Question #106
Which of the following Netmiko code snippets correctly uses the send_command() method and a valid device_type to retrieve interface IP information?
The correct answer is A. from netmiko import ConnectHandler router = { 'device_type': 'cisco_ios', 'host': '10.0.10.1', 'username': 'johndoe', 'password': 'Cisco!23!' } net_connect = ConnectHandler(**router) output = net_connect.send_command('show ip int brief') print(output). The correct Netmiko code snippet uses ConnectHandler with device_type='cisco_ios' and the send_command() method to retrieve the output of the 'show ip int brief' command.
Question
send_command() method and a valid device_type to retrieve interface IP information?Exhibit
Options
- Afrom netmiko import ConnectHandler router = { 'device_type': 'cisco_ios', 'host': '10.0.10.1', 'username': 'johndoe', 'password': 'Cisco!23!' } net_connect = ConnectHandler(**router) output = net_connect.send_command('show ip int brief') print(output)
- Bfrom netmiko import ConnectHandler router = { 'device_type': 'cisco_ios', 'host': '10.0.10.1', 'username': 'johndoe', 'password': 'Cisco!23!' } net_connect = ConnectHandler(**router) output = net_connect.command('show ip int brief') print(output)
- Cfrom netmiko import ConnectHandler router = { 'device_type': 'ios_xe', 'host': '10.0.10.1', 'username': 'johndoe', 'password': 'Cisco!23!' } net_connect = ConnectHandler(**router) output = net_connect.show_command('show ip int brief') print(output)
- Dfrom netmiko import ConnectHandler router = { 'device_type': 'cisco_ios_xe', 'host': '10.0.10.1', 'username': 'johndoe', 'password': 'Cisco!23!' } net_connect = ConnectHandler(**router) output = net_connect.command('show ip int brief') print(output)
How the community answered
(25 responses)- A80% (20)
- B4% (1)
- C12% (3)
- D4% (1)
Why each option
The correct Netmiko code snippet uses `ConnectHandler` with `device_type='cisco_ios'` and the `send_command()` method to retrieve the output of the 'show ip int brief' command.
This snippet correctly imports `ConnectHandler`, defines the device dictionary with the valid `device_type='cisco_ios'` (which applies to Cisco IOS XE devices), and uses the `send_command()` method, which is the standard and correct way in Netmiko to send a single command to a network device and capture its output.
This snippet incorrectly uses `net_connect.command()`. The correct method for sending a command and receiving output is `send_command()`.
This snippet incorrectly uses `net_connect.show_command()`. The correct method for sending a command and receiving output is `send_command()`.
This snippet incorrectly uses `net_connect.command()`. The correct method for sending a command and receiving output is `send_command()`.
Concept tested: Netmiko send_command and device_type
Source: https://ktbyers.github.io/netmiko/docs/netmiko/index.html
Topics
Community Discussion
No community discussion yet for this question.
