Die Palo Alto Jungs haben eine exzellente XML API implementiert die für die Firewalls als auch Panorama usw. funktioniert.
Um auf die API Dokumentation zuzugreifen einfach https://<firewall_ip>/api aufrufen.
Der User muss API Rechte haben.
Hier ein Beispiel zum Auslesen der ARP Tabelle.
Ich habe den SSL Zertifikatscheck in Python deaktiviert in meiner Lab Umgebung. Bitte nicht in Produktionsumgebungen verwenden!
#!/usr/bin/env python
# required pip packages: lxml, beautifulsoup4, tabulate
from bs4 import BeautifulSoup as BS
import urllib2
import ssl
import urllib
from tabulate import tabulate
username = "api_test"
password = "supersecurepassword"
firewall = "192.168.111.1"
#####################
# SSL ignore Cert Check (Lab Environment only!)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
#####################
# Req function
def req_api(command, key):
url = "https://%s/api/?key=%s&type=op&cmd=" % (firewall, key) + urllib.quote_plus(command)
res = urllib2.urlopen(url, context=ctx)
return res.read()
#####################
# API Key request
req_api_url = "https://%s/api/?type=keygen&user=%s&password=%s" % (firewall, username, password)
res_api_key = urllib2.urlopen(req_api_url, context=ctx)
soup = BS(res_api_key.read(), "lxml")
key = soup.find('key').text
#####################
# Get arp entrys
soup = BS(req_api("<show><arp><entry name = 'all'/></arp></show>", key), "lxml")
arp_buffer = []
for e in soup("entry"):
arp_buffer.append([e.status.text, e.ip.text, e.ttl.text, e.interface.text, e.port.text, e.mac.text])
print "#" * 120 + "\n> ARP Cache Count: %s\n" %(len(arp_buffer)) + "#" * 120
print tabulate(arp_buffer, headers=['Status', 'IP', 'TTL', 'Interface', 'Port', 'MAC'], tablefmt='orgtbl')
Ergebnis:
>.\palo_xml.py ######################################################################################################################## > ARP Cache Count: 14 ######################################################################################################################## | Status | IP | TTL | Interface | Port | MAC | |----------+---------------+-------+-------------+-------------+-------------------| | c | 192.168.0.1 | 1560 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.2 | 1058 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.5 | 1797 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.11 | 1779 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.12 | 1581 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.13 | 1787 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.30 | 1055 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.33 | 1542 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.40 | 1121 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.42 | 173 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.44 | 1799 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.45 | 910 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.52 | 1788 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee | | c | 192.168.0.57 | 1671 | ethernet1/3 | ethernet1/3 | c0:ff:ee:c0:ff:ee |


