{"id":13557308,"url":"https://github.com/dmachard/python-dnsdist-console","last_synced_at":"2025-05-01T19:30:51.496Z","repository":{"id":43485771,"uuid":"255154734","full_name":"dmachard/python-dnsdist-console","owner":"dmachard","description":"Python client for the dnsdist console","archived":false,"fork":false,"pushed_at":"2025-04-02T10:29:25.000Z","size":120,"stargazers_count":13,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T14:40:47.430Z","etag":null,"topics":["console","dns","dnsdist","dnsdist-console","powerdns","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmachard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-12T19:26:42.000Z","updated_at":"2025-04-02T10:27:30.000Z","dependencies_parsed_at":"2023-12-09T12:27:22.553Z","dependency_job_id":"14ceb944-12e6-4293-8800-8cd8e0942494","html_url":"https://github.com/dmachard/python-dnsdist-console","commit_stats":null,"previous_names":["dmachard/dnsdist_console","dmachard/dnsdist-console"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmachard%2Fpython-dnsdist-console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmachard%2Fpython-dnsdist-console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmachard%2Fpython-dnsdist-console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmachard%2Fpython-dnsdist-console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmachard","download_url":"https://codeload.github.com/dmachard/python-dnsdist-console/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251932608,"owners_count":21667179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["console","dns","dnsdist","dnsdist-console","powerdns","python"],"created_at":"2024-08-01T12:04:16.201Z","updated_at":"2025-05-01T19:30:50.499Z","avatar_url":"https://github.com/dmachard.png","language":"Python","funding_links":[],"categories":["Python","python"],"sub_categories":[],"readme":"# Python client for dnsdist console\n\nTool to interact with your dnsdist console from Python.\n\n![powerdns dnsdist 1.9.x](https://img.shields.io/badge/dnsdist%201.9.x-tested-green) ![powerdns dnsdist 1.8.x](https://img.shields.io/badge/dnsdist%201.8.x-tested-green) ![powerdns dnsdist 1.7.x](https://img.shields.io/badge/dnsdist%201.7.x-tested-green) ![powerdns dnsdist 1.6.x](https://img.shields.io/badge/dnsdist%201.6.x-tested-green) \n\n## Table of contents\n* [Installation](#installation)\n* [Generate console key](#generate-console-key)\n* [Generate hash password](#generate-hash-password)\n* [Run command](#run-command)\n* [Get statistics](#get-statistics)\n* [Display basic dashboard](#display-basic-dashboard)\n\n## Installation\n\n![python 3.12.x](https://img.shields.io/badge/python%203.12.x-tested-blue) ![python 3.11.x](https://img.shields.io/badge/python%203.11.x-tested-blue) ![python 3.10.x](https://img.shields.io/badge/python%203.10.x-tested-blue) ![python 3.9.x](https://img.shields.io/badge/python%203.9.x-tested-blue) ![python 3.8.x](https://img.shields.io/badge/python%203.8.x-tested-blue)\n\nThis module can be installed from [pypi](https://pypi.org/project/dnsdist_console/) website\n\n```python\npip install dnsdist_console\n```\n\n## Generate console key\n\nYou must configure your dnsdist load balancer to accept remote connection to the console.\nThis module can be used to generate the secret key as below.\n\nThe command in one line \n\n```bash\npython3 -c \"from dnsdist_console import Key;print(Key().generate())\"\nOTgmgAR6zbrfrYlKgsAAJn+by4faMqI1bVCvzacXMW0=\n```\n\nSave-it in your `/etc/dnsdist/dnsdist.conf` with the `setKey` directive.\n\n```\ncontrolSocket('0.0.0.0:5199')\nsetKey(\"GQpEpQoIuzA6kzgwDokX9JcXPXFvO1Emg1wAXToJ0ag=\")\n```\n\n## Generate hash password\n\nYou can use this module to generate a hash for the webserver of your dnsdist.\nSince 1.7.0 the password should be hashed and salted.\n\nThe command in one line \n\n```bash\npython3 -c \"from dnsdist_console import HashPassword as H;print(H().generate(\\\"bonjour\\\"))\"\n$scrypt$ln=10,p=1,r=8$SZmi+pjuZ4u7L4jhXIkLww==$VRW7BuYUjSVjkjDIK6J1VB/RWx2s4gbz+YXgflWspf8=\n```\n\n## Run command\n\nConfigure the client with the IP address and the TCP port of your dnsdist as well as the associated secret key. If the provided key is incorrect, an exception will be raised.\n\n```python\nfrom dnsdist_console import Console\n\nconsole_ip = \"127.0.0.1\"\nconsole_port = 5199\nconsole_key = \"GQpEpQoIuzA6kzgwDokX9JcXPXFvO1Emg1wAXToJ0ag=\"\n\nconsole = Console(host=console_ip,\n                  port=console_port, \n                  key=console_key)\n```\n\nPlease refer to the [dnsdist documentation](https://dnsdist.org/reference/config.html) for all available commands.\n\n```python\no = console.send_command(cmd=\"showVersion()\")\nprint(o)\ndnsdist 1.4.0\n\n```\n\n## Get statistics\n\nUse this module to extract some statistics on your dnsdist load balancer.\nStatistics are stored in a python dictionary.\n\n```python\nfrom dnsdist_console import Statistics\n\ns = Statistics(console=console)\nprint(s[\"global\"][\"queries\"])\n3993\n\n# get top queries\nprint(s[\"top-queries\"])\n[\n    {'entry': 'www.apple.com.', 'hits': '9'},\n    {'entry': 'www.facebook.com.', 'hits': '3'},\n    {'entry': 'www.microsoft.com.', 'hits': '3'}\n]\n\n\n# get top nx domain\nprint(s[\"top-nxdomain\"])\n[\n    {'entry': 'www.nxdomain.com.', 'hits': '1'}\n    \n]\n\n# get top clients\nprint(s[\"top-clients\"])\n[\n    {'entry': '127.0.0.1', 'hits': '21'}\n]\n```\n    \n## Display basic dashboard\n\nYou can use this client to display a dashboard of your dnsdist from your command line.\nThe dashboard is updated every second.\n\n```python\nfrom dnsdist_console import Dashboard\n\nDashboard(console=console)\n```\n\nRun your script and you will see something like below.\n\n```bash\nDashboard for dnsdist\n\nGlobal:\n        Uptime (seconds): 47735\n        Number of queries: 0\n        Query per second: 0\n        ACL drops: 0\n        Dynamic drops: 0\n        Rule drops: 0\n        CPU Usage (%s): 2.8\n        Cache hitrate: 0\nBackends:\n        #0 / 10.0.0.140:53 / -- / dns_others\n                Number of queries: 0\n                Query per second: 0.0\n                Number of drops: 0\n        #1 / 10.0.0.55:53 / -- / dns_internal\n                Number of queries: 0\n                Query per second: 0.0\n                Number of drops: 0\n        #2 / 8.8.8.8:53 / -- / dns_internet\n                Number of queries: 0\n                Query per second: 0.0\n                Number of drops: 0\n        #3 / 1.1.1.1:53 / dns_1 / --\n                Number of queries: 0\n                Query per second: 0.0\n                Number of drops: 0\n\nCtrl+C to exit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmachard%2Fpython-dnsdist-console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmachard%2Fpython-dnsdist-console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmachard%2Fpython-dnsdist-console/lists"}