Monday, October 2, 2023

Using Python and Netmiko to Access and Retrieve Palo Alto Firewall Data

In this post, I will be using the python code below to login a my Palo Alto Firewall using NETMIKO.
the code defines two functions that we will use to get the information we need from the Firewall.
note that you can replicate the function to add other (net_connect.send_commands)
then print out, or even more that you can also add more IP addresses 
for example: pan2_ip and pan3_ip then you will only need to use the last two lines of the code:
pan2_ip= get_int(pan2_ip)
print(pan2_ip)
import netmiko

pan_ip= '192.168.1.250'

username='python'
password='python1234'
device_type='paloalto_panos' #this must be one of the types supported by Netmiko
port='22'

#get the system information of the PANOS
def get_info(ip):
net_connect = netmiko.ConnectHandler(ip=ip, device_type=device_type, username=username,password=password, port=port)
return net_connect.send_command('show system info')
pan_info= get_info(pan_ip)
print(pan_info)

#get the IP information of the PANOS
def get_int(ip):
net_connect = netmiko.ConnectHandler(ip=ip, device_type=device_type, username=username,password=password, port=port)
return net_connect.send_command('show interface all')
pan_ip= get_int(pan_ip)
print(pan_ip)
#end

No comments:

Post a Comment

Securing Small Businesses: A Roadmap to Continuity and Confidence

  In an ever-expanding world of cyberspace, the prevalence of cyber-attacks grows daily. Allocating budgetary resources to network and cyber...