### Install unbound_console with YAML support Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Installs the unbound_console Python package with support for loading zone data from YAML files. This is the recommended installation method if YAML functionality is needed. ```bash pip install unbound_console[yaml] ``` -------------------------------- ### Execute a command on Unbound server in Python Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Executes a given command on the Unbound server using the configured RemoteControl client and prints the output. The 'status' command is used as an example. ```python o = rc.send_command(cmd="status") print(o) ``` -------------------------------- ### Install unbound_console without YAML support Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Installs the unbound_console Python package without YAML support. This is suitable if zone data will be loaded using the LocalZone object instead of YAML files. ```bash pip install unbound_console ``` -------------------------------- ### Load DNS Zone from YAML - Python Source: https://context7.com/dmachard/python-unbound-console/llms.txt Loads a complete DNS zone definition from a YAML formatted string into the Unbound server. Requires the 'unbound_console[yaml]' package to be installed. The input is a YAML string representing the zone and its records. ```python from unbound_console import RemoteControl rc = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Define zone in YAML format zone_yaml = """ zone: name: home.local. type: static records: - "router.home.local. 86400 IN A 192.168.0.1" - "nas.home.local. 86400 IN A 192.168.0.2" - "printer.home.local. 86400 IN A 192.168.0.3" - "192.168.0.1 86400 IN PTR router.home.local." - "192.168.0.2 86400 IN PTR nas.home.local." - "192.168.0.3 86400 IN PTR printer.home.local." """ # Load the zone into Unbound result = rc.load_zone(zone_yaml) print(result) # Output: ok ``` -------------------------------- ### Load zone data from YAML content in Python Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Loads zone data into the Unbound server from a YAML formatted string. This requires the unbound_console package to be installed with YAML support. The output of the operation is printed. ```python o = rc.load_zone(zone_data='') print(o) ``` -------------------------------- ### RemoteControl - Synchronous Client Initialization Source: https://context7.com/dmachard/python-unbound-console/llms.txt Demonstrates how to initialize the synchronous `RemoteControl` client for TCP (with or without TLS) and Unix socket connections. ```APIDOC ## RemoteControl - Synchronous Client ### Description The `RemoteControl` class provides synchronous communication with an Unbound DNS server's remote control interface. It supports TCP connections (with optional TLS encryption) and Unix socket connections for local server management. ### Method `RemoteControl(host=None, port=8953, unix_sock=None, server_cert=None, client_cert=None, client_key=None)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from unbound_console import RemoteControl # TCP connection without TLS (for testing/development) rc_tcp_no_tls = RemoteControl(host="127.0.0.1", port=8953) # TCP connection with TLS authentication (recommended for production) rc_tcp_tls = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Unix socket connection (for local server) rc_unix = RemoteControl(unix_sock="/var/run/unbound-console.sock") ``` ### Response #### Success Response (200) None (Initialization does not return a value, but raises exceptions on failure) #### Response Example None ``` -------------------------------- ### Bulk Operations with send_command (Python) Source: https://context7.com/dmachard/python-unbound-console/llms.txt Shows how to use the send_command method with the `data_list` parameter for bulk operations like adding multiple local zones or local data records. Requires an initialized RemoteControl client. ```python from unbound_console import RemoteControl rc = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Bulk add local zones (e.g., for ad blocking) domains_to_block = [ "ads.example.com always_nxdomain", "tracking.example.com always_nxdomain", "malware.example.com always_nxdomain", ] result = rc.send_command(cmd="local_zones", data_list=domains_to_block) print(result) # Bulk add local data records records = [ "server1.internal. 3600 IN A 192.168.1.10", "server2.internal. 3600 IN A 192.168.1.11", "server3.internal. 3600 IN A 192.168.1.12", ] result = rc.send_command(cmd="local_datas", data_list=records) print(result) ``` -------------------------------- ### Synchronous Client Initialization (Python) Source: https://context7.com/dmachard/python-unbound-console/llms.txt Initializes the synchronous RemoteControl client for interacting with Unbound. Supports TCP (with or without TLS) and Unix socket connections. TLS requires server and client certificates/keys. ```python from unbound_console import RemoteControl # TCP connection without TLS (for testing/development) rc = RemoteControl(host="127.0.0.1", port=8953) # TCP connection with TLS authentication (recommended for production) rc = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Unix socket connection (for local server) rc = RemoteControl(unix_sock="/var/run/unbound-console.sock") ``` -------------------------------- ### RemoteControlAsync - Asynchronous Client Initialization Source: https://context7.com/dmachard/python-unbound-console/llms.txt Illustrates how to initialize the asynchronous `RemoteControlAsync` client for TCP (with or without TLS) and Unix socket connections using asyncio. ```APIDOC ## RemoteControlAsync - Asynchronous Client ### Description The `RemoteControlAsync` class provides asyncio-compatible asynchronous communication with Unbound DNS servers. It offers the same functionality as `RemoteControl` but with async/await syntax for non-blocking operations. ### Method `RemoteControlAsync(host=None, port=8953, unix_sock=None, server_cert=None, client_cert=None, client_key=None)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import asyncio from unbound_console import RemoteControlAsync async def main(): # Create async client with TLS rc_async_tls = RemoteControlAsync( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Unix socket connection async rc_async_unix = RemoteControlAsync(unix_sock="/var/run/unbound-console.sock") # Execute commands asynchronously (example within main) status = await rc_async_tls.send_command(cmd="status") print(status) asyncio.run(main()) ``` ### Response #### Success Response (200) None (Initialization does not return a value, but raises exceptions on failure) #### Response Example None ``` -------------------------------- ### Execute bulk command on Unbound server in Python Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Executes a bulk command on the Unbound server, such as setting local zone configurations. A list of domain configurations is prepared and then sent using the send_command method with the 'local_zones' command. ```python domains_bulk = [] domains_bulk.append( "www.google.com always_nxdomain") o = rc.send_command(cmd="local_zones", data_list=domains_bulk) print(o) ``` -------------------------------- ### Bulk Commands - Execute Multiple Operations Source: https://context7.com/dmachard/python-unbound-console/llms.txt Explains how to use the `send_command` method with the `data_list` parameter for bulk operations like adding or removing multiple zones or data records. ```APIDOC ## Bulk Commands - Execute Multiple Operations ### Description The `send_command` method supports bulk operations through the `data_list` parameter for commands like `local_zones`, `local_zones_remove`, `local_datas`, and `local_datas_remove`. ### Method `send_command(cmd: str, data_list: list[str]) -> str` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from unbound_console import RemoteControl rc = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Bulk add local zones (e.g., for ad blocking) domains_to_block = [ "ads.example.com always_nxdomain", "tracking.example.com always_nxdomain", "malware.example.com always_nxdomain", ] result_zones = rc.send_command(cmd="local_zones", data_list=domains_to_block) print(result_zones) # Bulk add local data records records = [ "server1.internal. 3600 IN A 192.168.1.10", "server2.internal. 3600 IN A 192.168.1.11", "server3.internal. 3600 IN A 192.168.1.12", ] result_datas = rc.send_command(cmd="local_datas", data_list=records) print(result_datas) ``` ### Response #### Success Response (200) - **output** (str) - The string output from the executed unbound-control command, typically indicating success or failure of the bulk operation. #### Response Example ```json { "output": "OK" } ``` ``` -------------------------------- ### Asynchronous Zone Loading - Python Source: https://context7.com/dmachard/python-unbound-console/llms.txt Demonstrates asynchronous loading of DNS zones using the `RemoteControlAsync` class. It supports loading zones from both YAML strings and `LocalZone` objects, mirroring the synchronous API but within an `async` context. ```python import asyncio from unbound_console import RemoteControlAsync, LocalZone async def setup_dns_zones(): rc = RemoteControlAsync( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Load zone from YAML asynchronously zone_yaml = """ zone: name: services.local. type: static records: - "web.services.local. 3600 IN A 10.10.0.1" - "mail.services.local. 3600 IN A 10.10.0.2" """ result = await rc.load_zone(zone_yaml) print(f"YAML zone loaded: {result}") # Load zone from LocalZone object asynchronously zone = LocalZone( name="apps.local.", type="static", records=[ "frontend.apps.local. 3600 IN A 10.20.0.1", "backend.apps.local. 3600 IN A 10.20.0.2", ] ) result = await rc.load_zone(zone) print(f"LocalZone loaded: {result}") asyncio.run(setup_dns_zones()) ``` -------------------------------- ### Asynchronous Client Initialization and Usage (Python) Source: https://context7.com/dmachard/python-unbound-console/llms.txt Initializes and uses the asynchronous RemoteControlAsync client for non-blocking interaction with Unbound. Supports TLS and Unix socket connections. Demonstrates sending commands asynchronously. ```python import asyncio from unbound_console import RemoteControlAsync async def main(): # Create async client with TLS rc = RemoteControlAsync( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Execute commands asynchronously status = await rc.send_command(cmd="status") print(status) # Unix socket connection async rc_unix = RemoteControlAsync(unix_sock="/var/run/unbound-console.sock") status = await rc_unix.send_command(cmd="status") asyncio.run(main()) ``` -------------------------------- ### Execute Unbound Control Commands (Python) Source: https://context7.com/dmachard/python-unbound-console/llms.txt Demonstrates using the send_command method to execute various unbound-control commands, including status, stats, cache flush, cache dump, and adding local data records. Requires an initialized RemoteControl client. ```python from unbound_console import RemoteControl rc = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Get server status status = rc.send_command(cmd="status") print(status) # Output: version: 1.22.0 # verbosity: 1 # threads: 4 # modules: 3 [ validator iterator ] # uptime: 86400 seconds # options: control(ssl) # unbound (pid 1234) is running... # Get statistics stats = rc.send_command(cmd="stats_noreset") print(stats) # Flush cache for a domain result = rc.send_command(cmd="flush example.com") print(result) # Dump cache contents cache = rc.send_command(cmd="dump_cache") # Add local data record result = rc.send_command(cmd="local_data myhost.local. 3600 IN A 10.0.0.1") print(result) ``` -------------------------------- ### send_command - Execute Unbound Control Commands Source: https://context7.com/dmachard/python-unbound-console/llms.txt Details on using the `send_command` method to execute arbitrary unbound-control commands and retrieve their output. ```APIDOC ## send_command - Execute Unbound Control Commands ### Description The `send_command` method executes any unbound-control command and returns the output. It supports all standard Unbound commands including status queries, cache management, zone operations, and statistics retrieval. ### Method `send_command(cmd: str, data_list: list[str] | None = None) -> str` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from unbound_console import RemoteControl rc = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Get server status status = rc.send_command(cmd="status") print(status) # Get statistics stats = rc.send_command(cmd="stats_noreset") print(stats) # Flush cache for a domain result = rc.send_command(cmd="flush example.com") print(result) # Dump cache contents cache = rc.send_command(cmd="dump_cache") # Add local data record result = rc.send_command(cmd="local_data myhost.local. 3600 IN A 10.0.0.1") print(result) ``` ### Response #### Success Response (200) - **output** (str) - The string output from the executed unbound-control command. #### Response Example ```json { "output": "version: 1.22.0\nmodules: 3 [ validator iterator ]\nunbound (pid 1234) is running..." } ``` ``` -------------------------------- ### Configure RemoteControl client in Python Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Configures the RemoteControl client for connecting to an Unbound server using TLS. It specifies connection details like host, port, and paths to server and client certificates and keys. Alternatively, a Unix socket can be used. ```python rc = RemoteControl(host="127.0.0.1", port=8953, server_cert = "/etc/unbound/unbound_server.pem", client_cert= "/etc/unbound/unbound_control.pem", client_key= "/etc/unbound/unbound_control.key") ``` -------------------------------- ### Unbound Server Configuration - Conf Source: https://context7.com/dmachard/python-unbound-console/llms.txt Provides the essential configuration snippet for the `unbound.conf` file required to enable remote control functionality for the Unbound DNS server. This allows the python-unbound-console library to connect and manage zones. ```conf server: remote-control: control-enable: yes control-interface: 127.0.0.1 control-port: 8953 # Optional: Use TLS for secure control connection # control-key-file: "/etc/unbound/unbound_control.key" # control-cert-file: "/etc/unbound/unbound_control.pem" # server-key-file: "/etc/unbound/unbound_server.key" # server-cert-file: "/etc/unbound/unbound_server.pem" ``` -------------------------------- ### Load zone data from LocalZone object in Python Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Loads zone data into the Unbound server using a LocalZone object. This method is an alternative to using YAML files for defining zone records. The result is then printed. ```python from unbound_console import LocalZone zone = LocalZone( name="home", type="static", records=[ "router.home. 86400 IN A 192.168.0.1", "192.168.0.1 86400 IN PTR router.test.", ], ) o = rc.load_zone(zone_data=zone) print(o) ``` -------------------------------- ### Programmatic Zone Definition with LocalZone - Python Source: https://context7.com/dmachard/python-unbound-console/llms.txt Defines a DNS zone programmatically using the `LocalZone` dataclass, bypassing the need for YAML. This object can be directly passed to the `load_zone` method. It supports various zone types. ```python from unbound_console import RemoteControl, LocalZone rc = RemoteControl( host="127.0.0.1", port=8953, server_cert="/etc/unbound/unbound_server.pem", client_cert="/etc/unbound/unbound_control.pem", client_key="/etc/unbound/unbound_control.key" ) # Create zone programmatically zone = LocalZone( name="internal.company.com.", type="static", records=[ "app.internal.company.com. 3600 IN A 10.0.1.10", "api.internal.company.com. 3600 IN A 10.0.1.11", "db.internal.company.com. 3600 IN A 10.0.1.12", "cache.internal.company.com. 3600 IN A 10.0.1.13", "10.0.1.10 3600 IN PTR app.internal.company.com.", "10.0.1.11 3600 IN PTR api.internal.company.com.", ] ) # Load zone using LocalZone object result = rc.load_zone(zone) print(result) # Output: ok # Zone types: static, deny, refuse, redirect, transparent, # typetransparent, inform, inform_deny, always_transparent, # always_refuse, always_nxdomain, noview, nodefault ``` -------------------------------- ### Import RemoteControl module in Python Source: https://github.com/dmachard/python-unbound-console/blob/master/README.md Imports the necessary RemoteControl class from the unbound_console library to enable interaction with the Unbound server. ```python from unbound_console import RemoteControl ``` -------------------------------- ### Bulk Remove Local Zones - Python Source: https://context7.com/dmachard/python-unbound-console/llms.txt Removes multiple local DNS zones from the Unbound server in a single operation. This function requires a list of zone names to be removed. ```python zones_to_remove = [ "ads.example.com", "tracking.example.com", ] result = rc.send_command(cmd="local_zones_remove", data_list=zones_to_remove) print(result) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.