#!/usr/bin/env python3 import json import re import urllib.error import urllib.request import paramiko PASS = "Bbt9115xty9176!" CF = "https://api.cloudflare.com/client/v4" def get_token(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("10.10.0.1", username="admin", password=PASS, timeout=15) _, o, e = c.exec_command("cat /usr/local/etc/wan-dns-failover.env", timeout=30) o.channel.recv_exit_status() text = (o.read() + e.read()).decode() c.close() return re.search(r"CLOUDFLARE_API_TOKEN=([^\s\"']+)", text).group(1) def call(tok, path): req = urllib.request.Request( CF + path, headers={"Authorization": f"Bearer {tok}", "Content-Type": "application/json"}, ) with urllib.request.urlopen(req, timeout=60) as r: return json.load(r) def main(): tok = get_token() page = 1 while page <= 20: res = call(tok, f"/zones?per_page=50&page={page}") for z in res.get("result", []): print(f"{z['name']:40} {z['status']:10} {z['id']}") if len(res.get("result", [])) < 50: break page += 1 if __name__ == "__main__": main()