Running a CLI command from Python using paramiko

Reply
Highlighted
L0 Member

Running a CLI command from Python using paramiko

I have a very simple python script that uses ssh=paramiko.SSHClient(), ssh.connect (host, 22, user, password), stdin, stdout, stderr=ssh.exec_command(command), and for line in stdout.read().splitlines(): print(line). 

When I set host, user, password and command, e.g. "show ip int brief", to connect to a Cisco router, everything works fine and the script prints out the results that I expect. However, when I set them to connect to a PAN firewall, e.g. command="show clock", my script connects to the FW, which I confirm by looking in the FW's system log, but all I get returned is the 'Number of failed attempts since last successful login: 0' message?

 

Any ideas - I'm sure I'm just missing something basic. Do I need to import any of the PAN packages or can I just run run simple CLI commands using paramiko?

 

PS: I sleep for 20 seconds after connecting before running the ssh.exec_command()

 

Thanks,

Ian

L0 Member

Re: Running a CLI command from Python using paramiko

Solved by:

import pandevice
my_fw = firewall.Firewall(host, user, password)
response = my_fw.op(command2, xml=True)
print(response)

 

The response is a page of XML, so needs to be interpreted, but I do get the answers I want

Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the Live Community as a whole!

The Live Community thanks you for your participation!