Files
SnarfCode/scripts/dump_firewall_policies.py

25 lines
1.1 KiB
Python

import requests
import urllib3
import json
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
s = requests.Session()
s.verify = False
r = s.post('https://14.44.4.1/api/auth/login', json={'username': 'snarf', 'password': 'Katzir476!!!'})
csrf = r.headers.get('x-csrf-token') or r.cookies.get('csrf_token')
headers = {'X-CSRF-Token': csrf} if csrf else {}
res = s.get('https://14.44.4.1/proxy/network/v2/api/site/default/firewall-policies', headers=headers)
policies = res.json()
print(f"Found {len(policies)} policies:")
for p in policies:
print(f"Index {p.get('index')}: {p.get('name')} | action={p.get('action')} | enabled={p.get('enabled')}")
src = p.get('source', {})
dst = p.get('destination', {})
print(f" Src: zone={src.get('zone_id')} net={src.get('network_id')} ip={src.get('ip_addresses')}")
print(f" Dst: zone={dst.get('zone_id')} net={dst.get('network_id')} ip={dst.get('ip_addresses')} port={dst.get('port_ranges')}")
print(f" States: {p.get('connection_states')}, state_type: {p.get('connection_state_type')}")