Python script to get PAN-OS of Palo Alto Networks Firewall/Panorama

Following script can be used to pull PAN-OS of Palo Alto Networks firewall/Panorama. You have to generate your own key as it is dependent on your user name and password.

import requests
import urllib
import xml.etree.ElementTree as ET

firewall=range(50,88)
urlhttp="https://"
urlip= "10.50.243."
key = "key=LUFRPT14MW5xOEo1R09KVlBZNnpnemh0VHRBOWl6TGM9bXcwM3JHUGVhRlNiY0dCR0srNERUQT09"

for i in firewall:

    ip=urlip+str(i)
    completeurl = urlhttp +ip + "/api/?type=op&cmd=&"+key

    try:
        res = requests.get(completeurl,stream=True,verify=False,timeout=4)
        Tree = ET.parse(res.raw)
        root=Tree.getroot()
        c=root.attrib.values()
        if c[0]=='success':
            for child in root.iter('system'):
                print (child.find('ip-address').text +'t'+ child.find('sw-version').text +'t'+ child.find('model').text )
        else:
            print(ip+'t'+'Error occured')
    except requests.exceptions.Timeout:
        print(ip+'t'+'Error occured')
        continue
    except requests.exceptions.TooManyRedirects:
        print(ip+'t'+'Error occured')
        continue
    except requests.exceptions.RequestException as e:
        print(ip+'t'+'Error occured')
        continue

 

Advertisements
This entry was posted in Python. Bookmark the permalink.