Paramiko with PaloAlto

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Paramiko with PaloAlto

L0 Member

Hi There,

 

I am very new to Python scripting and have started to learn through my lab PaloAlto Firewall.

I wrote a basic script to just return me the output of an operational command. This script works on my lab SRX but hangs on the PaloAlto.

 

The code snippet : (indentation is correct)

root# vi PAoutTest.py

#!/usr/bin/python

import paramiko
import time
import inspect

 

ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

timeout = 30

endtime = time.time() + timeout

iin = paramiko.sys.stdin
out = paramiko.sys.stdout
err = paramiko.sys.stderr

ssh.connect("x.x.x.x",username="xxxxx",password="xxxx")

iin, out, err = ssh.exec_command("show clock")

print out
#print out.read()

while not out.channel.eof_received:
time.sleep(1)
if time.time() > endtime:
out.channel.close()
break
print out.read()

 

I have included a while loop because without it the script would just hang forever and I have to manually kill the process.

So after the while loop the script times out without providing any output.

 

Is this not possible with PaloAlto or only way to automate is via API?

 

Please help.

 

2 REPLIES 2

L2 Linker

Yes it is possible to log into the Palo Alto using Paramiko, as long as you get all the timing and everything correct.

I use this instead of using exec, I believe exec is only able to run one command.

 

channel = ssh.invoke_shell()
output = channel.recv(10000)
print output
print "connected to device"


channel.send('show interface all\n')
output3 = channel.recv(1000000)

  • 5281 Views
  • 2 replies
  • 0 Likes
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 LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!