def commit_force(self): """Issues a commit to firewall""" cf = requests.get('https://' + self.ip + '/api/?type=commit&' + \ 'cmd=<commit><force></force></commit>&key=' + \ keys.pan_vm_key(), verify=False) if cf.status_code == 200: print(f'Commit to {self.ip} successful!')
def platform_info(host): api_call = 'https://' + host + '/api/?type=op&cmd=<show><system><info></info>' api_call += '</system></show>&key=' + keys.pa_vm_key() response = requests.get(api_call, verify=False) if response.status_code == 200: apikey = keys.pa_vm_key() return apikey else: apikey = keys.pan_vm_key() return apikey
def all_connected_fws_to_file(self): """Gets all firewalls connected to panorama. Retrieves the firewall ip-addresses and writes to a file named 'fwips.txt'""" output = requests.get('https://' + self.ip + '/api/?type=op&cmd=<show>' '<devices><all></all></devices></show>&key=' + keys.pan_vm_key(), verify=False) data = output.text root = ET.fromstring(data) with open('fwips.txt', mode='a+') as f: for elem in root.iter(): if elem.tag == 'ip-address': node = elem for item in node.iter(): fw_ip = item.text + '\n' f.write(fw_ip)
def all_connected_fws(self): """Gets all firewalls connected to panorama. Formats the XML data returned writes the firewall ip-addresses to a file named 'fwips.txt' """ output = requests.get('https://' + self.ip + '/api/?type=op&cmd=<show>' '<devices><all></all></devices></show>&key=' + keys.pan_vm_key(), verify=False) data = output.text root = ET.fromstring(data) fwips = [] for elem in root.iter(): if elem.tag == 'ip-address': node = elem fwip = node.text # Retrieve string format fwips.append(fwip) return fwips
import xml.etree.cElementTree as ET import requests from pandevice import panorama from pandevice import policies from Keys import keys from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) host = '10.46.164.193' key = '&key=' + keys.pan_vm_key() def dg_hierarchy_xpath(): xpath = '/api/?type=op&cmd=<show><dg-hierarchy></' xpath += 'dg-hierarchy></show>' return xpath def dg_api_call(): api_xpath = 'https://' + host + dg_hierarchy_xpath() + key api_call = requests.get(api_xpath, verify=False) return api_call.text def list_dg(): dg_list = [] root = ET.fromstring(dg_api_call()) for item in root.iter(): if 'name' in item.attrib:
def __init__(self, ip): """PAWN class instantiation""" self.ip = ip self.fw_key = keys.pa_vm_key() self.pan_key = keys.pan_vm_key()