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

urlip= "10.50.243."
key = "key=LUFRPT14MW5xOEo1R09KVlBZNnpnemh0VHRBOWl6TGM9bXcwM3JHUGVhRlNiY0dCR0srNERUQT09"

for i in firewall:

    completeurl = urlhttp +ip + "/api/?type=op&cmd=&"+key

        res = requests.get(completeurl,stream=True,verify=False,timeout=4)
        Tree = ET.parse(res.raw)
        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 )
            print(ip+'t'+'Error occured')
    except requests.exceptions.Timeout:
        print(ip+'t'+'Error occured')
    except requests.exceptions.TooManyRedirects:
        print(ip+'t'+'Error occured')
    except requests.exceptions.RequestException as e:
        print(ip+'t'+'Error occured')


This entry was posted in Python. Bookmark the permalink.