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 {} # Get sites r_sites = s.get('https://14.44.4.1/proxy/network/api/self/sites', headers=headers) print("Sites status:", r_sites.status_code) sites = r_sites.json().get('data', []) site_name = sites[0]['name'] if sites else 'default' print("Site name:", site_name) # Get networks r_net = s.get(f'https://14.44.4.1/proxy/network/api/s/{site_name}/rest/networkconf', headers=headers) print("Networks:") for n in r_net.json().get('data', []): print(f" {n.get('name')}: subnet={n.get('ip_subnet')}, vlan={n.get('vlan')}, purpose={n.get('purpose')}, isolation={n.get('isolation')}") # Get firewall rules r_fw = s.get(f'https://14.44.4.1/proxy/network/api/s/{site_name}/rest/firewallrule', headers=headers) print("\nFirewall Rules:") for rule in r_fw.json().get('data', []): print(f" Rule #{rule.get('rule_index')}: {rule.get('name')} | ruleset={rule.get('ruleset')} | action={rule.get('action')} | enabled={rule.get('enabled')}") print(f" src={rule.get('src_networkconf_id') or rule.get('src_address') or rule.get('src_firewallgroup_ids')} dst={rule.get('dst_networkconf_id') or rule.get('dst_address') or rule.get('dst_firewallgroup_ids')}") # Get client nutserver r_client = s.get(f'https://14.44.4.1/proxy/network/api/s/{site_name}/stat/sta', headers=headers) for c in r_client.json().get('data', []): if c.get('ip') == '14.4.4.44' or 'nut' in c.get('hostname', '').lower() or 'nut' in c.get('name', '').lower(): print("\nNut Client:", c.get('name'), c.get('hostname'), c.get('ip'), c.get('mac'), c.get('network_id'), c.get('essid'), c.get('is_guest'))