libknot 3.2.9__tar.gz → 3.2.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libknot-3.2.10/PKG-INFO +171 -0
- libknot-3.2.10/libknot.egg-info/PKG-INFO +171 -0
- {libknot-3.2.9 → libknot-3.2.10}/setup.py +1 -1
- libknot-3.2.9/PKG-INFO +0 -173
- libknot-3.2.9/libknot.egg-info/PKG-INFO +0 -173
- {libknot-3.2.9 → libknot-3.2.10}/README.md +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/libknot/__init__.py +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/libknot/control.py +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/libknot/dname.py +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/libknot/probe.py +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/libknot.egg-info/SOURCES.txt +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/libknot.egg-info/dependency_links.txt +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/libknot.egg-info/top_level.txt +0 -0
- {libknot-3.2.9 → libknot-3.2.10}/setup.cfg +0 -0
libknot-3.2.10/PKG-INFO
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: libknot
|
|
3
|
+
Version: 3.2.10
|
|
4
|
+
Summary: Python bindings for libknot
|
|
5
|
+
Home-page: https://gitlab.nic.cz/knot/knot-dns
|
|
6
|
+
Author: Daniel Salzman
|
|
7
|
+
Author-email: daniel.salzman@nic.cz
|
|
8
|
+
License: GPL-3.0
|
|
9
|
+
Description: # Libknot API in Python
|
|
10
|
+
|
|
11
|
+
A Python interface for managing the Knot DNS daemon.
|
|
12
|
+
|
|
13
|
+
# Table of contents
|
|
14
|
+
|
|
15
|
+
* [Introduction](#introduction)
|
|
16
|
+
* [Control module](#control-module)
|
|
17
|
+
+ [Usage](#using-the-control-module)
|
|
18
|
+
+ [Example](#control-module-example)
|
|
19
|
+
* [Probe module](#probe-module)
|
|
20
|
+
+ [Usage](#using-the-probe-module)
|
|
21
|
+
+ [Example](#probe-module-example)
|
|
22
|
+
* [Dname module](#dname-module)
|
|
23
|
+
+ [Usage](#using-the-dname-module)
|
|
24
|
+
+ [Example](#dname-module-example)
|
|
25
|
+
|
|
26
|
+
## Introduction
|
|
27
|
+
|
|
28
|
+
If the shared `libknot.so` library isn't available in the library search path, it's
|
|
29
|
+
necessary to load the library first, e.g.:
|
|
30
|
+
|
|
31
|
+
```python3
|
|
32
|
+
import libknot
|
|
33
|
+
libknot.Knot("/usr/lib/libknot.so")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Control module
|
|
37
|
+
|
|
38
|
+
Using this module it's possible to create scripts for efficient tasks that
|
|
39
|
+
would require complex shell scripts with multiple calls of `knotc`. For
|
|
40
|
+
communication with the daemon it uses the same mechanism as the `knotc` utility,
|
|
41
|
+
i.e. communication via a Unix socket.
|
|
42
|
+
|
|
43
|
+
The module API is stored in `libknot.control`.
|
|
44
|
+
|
|
45
|
+
### Using the Control module
|
|
46
|
+
|
|
47
|
+
The module usage consists of several steps:
|
|
48
|
+
|
|
49
|
+
* Initialization and connection to the daemon control socket.
|
|
50
|
+
* One or more control operations. An operation is called by sending a command
|
|
51
|
+
with optional data to the daemon. The operation result has to be received
|
|
52
|
+
afterwards.
|
|
53
|
+
* Closing the connection and deinitialization.
|
|
54
|
+
|
|
55
|
+
### Control module example
|
|
56
|
+
|
|
57
|
+
```python3
|
|
58
|
+
import json
|
|
59
|
+
import libknot.control
|
|
60
|
+
|
|
61
|
+
# Initialization
|
|
62
|
+
ctl = libknot.control.KnotCtl()
|
|
63
|
+
ctl.connect("/var/run/knot/knot.sock")
|
|
64
|
+
ctl.set_timeout(60)
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
# Operation without parameters
|
|
68
|
+
ctl.send_block(cmd="conf-begin")
|
|
69
|
+
resp = ctl.receive_block()
|
|
70
|
+
|
|
71
|
+
# Operation with parameters
|
|
72
|
+
ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test")
|
|
73
|
+
resp = ctl.receive_block()
|
|
74
|
+
|
|
75
|
+
ctl.send_block(cmd="conf-commit")
|
|
76
|
+
resp = ctl.receive_block()
|
|
77
|
+
|
|
78
|
+
# Operation with a result displayed in JSON format
|
|
79
|
+
ctl.send_block(cmd="conf-read", section="zone", item="domain")
|
|
80
|
+
resp = ctl.receive_block()
|
|
81
|
+
print(json.dumps(resp, indent=4))
|
|
82
|
+
except libknot.control.KnotCtlError as exc:
|
|
83
|
+
# Print libknot error
|
|
84
|
+
print(exc)
|
|
85
|
+
finally:
|
|
86
|
+
# Deinitialization
|
|
87
|
+
ctl.send(libknot.control.KnotCtlType.END)
|
|
88
|
+
ctl.close()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```python3
|
|
92
|
+
# List configured zones (including catalog member ones)
|
|
93
|
+
ctl.send_block(cmd="conf-list", flags="z")
|
|
94
|
+
resp = ctl.receive_block()
|
|
95
|
+
for zone in resp['zone']:
|
|
96
|
+
print(zone)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Probe module
|
|
100
|
+
|
|
101
|
+
Using this module it's possible to receive traffic data from a running daemon with
|
|
102
|
+
active probe module.
|
|
103
|
+
|
|
104
|
+
The module API is stored in `libknot.probe`.
|
|
105
|
+
|
|
106
|
+
### Using the Probe module
|
|
107
|
+
|
|
108
|
+
The module usage consists of several steps:
|
|
109
|
+
|
|
110
|
+
* Initialization of one or more probe channels
|
|
111
|
+
* Periodical receiving of data units from the channels and data processing
|
|
112
|
+
|
|
113
|
+
### Probe module example
|
|
114
|
+
|
|
115
|
+
```python3
|
|
116
|
+
import libknot.probe
|
|
117
|
+
|
|
118
|
+
# Initialization of the first probe channel stored in `/run/knot`
|
|
119
|
+
probe = libknot.probe.KnotProbe("/run/knot", 1)
|
|
120
|
+
|
|
121
|
+
# Array for storing up to 8 data units
|
|
122
|
+
data = libknot.probe.KnotProbeDataArray(8)
|
|
123
|
+
while (True):
|
|
124
|
+
# Receiving data units with timeout of 1000 ms
|
|
125
|
+
if probe.consume(data, 1000) > 0:
|
|
126
|
+
# Printing received data units in the default format
|
|
127
|
+
for item in data:
|
|
128
|
+
print(item)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Dname module
|
|
132
|
+
|
|
133
|
+
This module provides a few dname-related operations.
|
|
134
|
+
|
|
135
|
+
### Using the Dname module
|
|
136
|
+
|
|
137
|
+
The dname object is initialized from a string with textual dname.
|
|
138
|
+
Then the dname can be reformatted to wire format or back to textual format.
|
|
139
|
+
|
|
140
|
+
### Dname module example
|
|
141
|
+
|
|
142
|
+
```python3
|
|
143
|
+
import libknot.dname
|
|
144
|
+
|
|
145
|
+
dname1 = libknot.dname.KnotDname("knot-dns.cz")
|
|
146
|
+
print("%s: wire: %s size: %u" % (dname1.str(), dname1.wire(), dname1.size()))
|
|
147
|
+
|
|
148
|
+
dname2 = libknot.dname.KnotDname("e\\120ample.c\om.")
|
|
149
|
+
print("%s: wire: %s size: %u" % (dname2.str(), dname2.wire(), dname2.size()))
|
|
150
|
+
|
|
151
|
+
dname3 = libknot.dname.KnotDname(dname_wire=b'\x02cz\x00')
|
|
152
|
+
print("%s: wire: %s size: %u" % (dname3.str(), dname3.wire(), dname3.size()))
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
knot-dns.cz.: wire: b'\x08knot-dns\x02cz\x00' size: 13
|
|
157
|
+
example.com.: wire: b'\x07example\x03com\x00' size: 13
|
|
158
|
+
cz.: wire: b'\x02cz\x00' size: 4
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Platform: UNKNOWN
|
|
162
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
163
|
+
Classifier: Intended Audience :: Developers
|
|
164
|
+
Classifier: Intended Audience :: System Administrators
|
|
165
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
166
|
+
Classifier: Programming Language :: Python :: 3
|
|
167
|
+
Classifier: Topic :: Internet :: Name Service (DNS)
|
|
168
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
169
|
+
Classifier: Topic :: System :: Systems Administration
|
|
170
|
+
Requires-Python: >=3.5
|
|
171
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: libknot
|
|
3
|
+
Version: 3.2.10
|
|
4
|
+
Summary: Python bindings for libknot
|
|
5
|
+
Home-page: https://gitlab.nic.cz/knot/knot-dns
|
|
6
|
+
Author: Daniel Salzman
|
|
7
|
+
Author-email: daniel.salzman@nic.cz
|
|
8
|
+
License: GPL-3.0
|
|
9
|
+
Description: # Libknot API in Python
|
|
10
|
+
|
|
11
|
+
A Python interface for managing the Knot DNS daemon.
|
|
12
|
+
|
|
13
|
+
# Table of contents
|
|
14
|
+
|
|
15
|
+
* [Introduction](#introduction)
|
|
16
|
+
* [Control module](#control-module)
|
|
17
|
+
+ [Usage](#using-the-control-module)
|
|
18
|
+
+ [Example](#control-module-example)
|
|
19
|
+
* [Probe module](#probe-module)
|
|
20
|
+
+ [Usage](#using-the-probe-module)
|
|
21
|
+
+ [Example](#probe-module-example)
|
|
22
|
+
* [Dname module](#dname-module)
|
|
23
|
+
+ [Usage](#using-the-dname-module)
|
|
24
|
+
+ [Example](#dname-module-example)
|
|
25
|
+
|
|
26
|
+
## Introduction
|
|
27
|
+
|
|
28
|
+
If the shared `libknot.so` library isn't available in the library search path, it's
|
|
29
|
+
necessary to load the library first, e.g.:
|
|
30
|
+
|
|
31
|
+
```python3
|
|
32
|
+
import libknot
|
|
33
|
+
libknot.Knot("/usr/lib/libknot.so")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Control module
|
|
37
|
+
|
|
38
|
+
Using this module it's possible to create scripts for efficient tasks that
|
|
39
|
+
would require complex shell scripts with multiple calls of `knotc`. For
|
|
40
|
+
communication with the daemon it uses the same mechanism as the `knotc` utility,
|
|
41
|
+
i.e. communication via a Unix socket.
|
|
42
|
+
|
|
43
|
+
The module API is stored in `libknot.control`.
|
|
44
|
+
|
|
45
|
+
### Using the Control module
|
|
46
|
+
|
|
47
|
+
The module usage consists of several steps:
|
|
48
|
+
|
|
49
|
+
* Initialization and connection to the daemon control socket.
|
|
50
|
+
* One or more control operations. An operation is called by sending a command
|
|
51
|
+
with optional data to the daemon. The operation result has to be received
|
|
52
|
+
afterwards.
|
|
53
|
+
* Closing the connection and deinitialization.
|
|
54
|
+
|
|
55
|
+
### Control module example
|
|
56
|
+
|
|
57
|
+
```python3
|
|
58
|
+
import json
|
|
59
|
+
import libknot.control
|
|
60
|
+
|
|
61
|
+
# Initialization
|
|
62
|
+
ctl = libknot.control.KnotCtl()
|
|
63
|
+
ctl.connect("/var/run/knot/knot.sock")
|
|
64
|
+
ctl.set_timeout(60)
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
# Operation without parameters
|
|
68
|
+
ctl.send_block(cmd="conf-begin")
|
|
69
|
+
resp = ctl.receive_block()
|
|
70
|
+
|
|
71
|
+
# Operation with parameters
|
|
72
|
+
ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test")
|
|
73
|
+
resp = ctl.receive_block()
|
|
74
|
+
|
|
75
|
+
ctl.send_block(cmd="conf-commit")
|
|
76
|
+
resp = ctl.receive_block()
|
|
77
|
+
|
|
78
|
+
# Operation with a result displayed in JSON format
|
|
79
|
+
ctl.send_block(cmd="conf-read", section="zone", item="domain")
|
|
80
|
+
resp = ctl.receive_block()
|
|
81
|
+
print(json.dumps(resp, indent=4))
|
|
82
|
+
except libknot.control.KnotCtlError as exc:
|
|
83
|
+
# Print libknot error
|
|
84
|
+
print(exc)
|
|
85
|
+
finally:
|
|
86
|
+
# Deinitialization
|
|
87
|
+
ctl.send(libknot.control.KnotCtlType.END)
|
|
88
|
+
ctl.close()
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```python3
|
|
92
|
+
# List configured zones (including catalog member ones)
|
|
93
|
+
ctl.send_block(cmd="conf-list", flags="z")
|
|
94
|
+
resp = ctl.receive_block()
|
|
95
|
+
for zone in resp['zone']:
|
|
96
|
+
print(zone)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Probe module
|
|
100
|
+
|
|
101
|
+
Using this module it's possible to receive traffic data from a running daemon with
|
|
102
|
+
active probe module.
|
|
103
|
+
|
|
104
|
+
The module API is stored in `libknot.probe`.
|
|
105
|
+
|
|
106
|
+
### Using the Probe module
|
|
107
|
+
|
|
108
|
+
The module usage consists of several steps:
|
|
109
|
+
|
|
110
|
+
* Initialization of one or more probe channels
|
|
111
|
+
* Periodical receiving of data units from the channels and data processing
|
|
112
|
+
|
|
113
|
+
### Probe module example
|
|
114
|
+
|
|
115
|
+
```python3
|
|
116
|
+
import libknot.probe
|
|
117
|
+
|
|
118
|
+
# Initialization of the first probe channel stored in `/run/knot`
|
|
119
|
+
probe = libknot.probe.KnotProbe("/run/knot", 1)
|
|
120
|
+
|
|
121
|
+
# Array for storing up to 8 data units
|
|
122
|
+
data = libknot.probe.KnotProbeDataArray(8)
|
|
123
|
+
while (True):
|
|
124
|
+
# Receiving data units with timeout of 1000 ms
|
|
125
|
+
if probe.consume(data, 1000) > 0:
|
|
126
|
+
# Printing received data units in the default format
|
|
127
|
+
for item in data:
|
|
128
|
+
print(item)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Dname module
|
|
132
|
+
|
|
133
|
+
This module provides a few dname-related operations.
|
|
134
|
+
|
|
135
|
+
### Using the Dname module
|
|
136
|
+
|
|
137
|
+
The dname object is initialized from a string with textual dname.
|
|
138
|
+
Then the dname can be reformatted to wire format or back to textual format.
|
|
139
|
+
|
|
140
|
+
### Dname module example
|
|
141
|
+
|
|
142
|
+
```python3
|
|
143
|
+
import libknot.dname
|
|
144
|
+
|
|
145
|
+
dname1 = libknot.dname.KnotDname("knot-dns.cz")
|
|
146
|
+
print("%s: wire: %s size: %u" % (dname1.str(), dname1.wire(), dname1.size()))
|
|
147
|
+
|
|
148
|
+
dname2 = libknot.dname.KnotDname("e\\120ample.c\om.")
|
|
149
|
+
print("%s: wire: %s size: %u" % (dname2.str(), dname2.wire(), dname2.size()))
|
|
150
|
+
|
|
151
|
+
dname3 = libknot.dname.KnotDname(dname_wire=b'\x02cz\x00')
|
|
152
|
+
print("%s: wire: %s size: %u" % (dname3.str(), dname3.wire(), dname3.size()))
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
knot-dns.cz.: wire: b'\x08knot-dns\x02cz\x00' size: 13
|
|
157
|
+
example.com.: wire: b'\x07example\x03com\x00' size: 13
|
|
158
|
+
cz.: wire: b'\x02cz\x00' size: 4
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Platform: UNKNOWN
|
|
162
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
163
|
+
Classifier: Intended Audience :: Developers
|
|
164
|
+
Classifier: Intended Audience :: System Administrators
|
|
165
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
166
|
+
Classifier: Programming Language :: Python :: 3
|
|
167
|
+
Classifier: Topic :: Internet :: Name Service (DNS)
|
|
168
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
169
|
+
Classifier: Topic :: System :: Systems Administration
|
|
170
|
+
Requires-Python: >=3.5
|
|
171
|
+
Description-Content-Type: text/markdown
|
libknot-3.2.9/PKG-INFO
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: libknot
|
|
3
|
-
Version: 3.2.9
|
|
4
|
-
Summary: Python bindings for libknot
|
|
5
|
-
Home-page: https://gitlab.nic.cz/knot/knot-dns
|
|
6
|
-
Author: Daniel Salzman
|
|
7
|
-
Author-email: daniel.salzman@nic.cz
|
|
8
|
-
License: GPL-3.0
|
|
9
|
-
Platform: UNKNOWN
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Intended Audience :: System Administrators
|
|
13
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Topic :: Internet :: Name Service (DNS)
|
|
16
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
-
Classifier: Topic :: System :: Systems Administration
|
|
18
|
-
Requires-Python: >=3.5
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
|
|
21
|
-
# Libknot API in Python
|
|
22
|
-
|
|
23
|
-
A Python interface for managing the Knot DNS daemon.
|
|
24
|
-
|
|
25
|
-
# Table of contents
|
|
26
|
-
|
|
27
|
-
* [Introduction](#introduction)
|
|
28
|
-
* [Control module](#control-module)
|
|
29
|
-
+ [Usage](#using-the-control-module)
|
|
30
|
-
+ [Example](#control-module-example)
|
|
31
|
-
* [Probe module](#probe-module)
|
|
32
|
-
+ [Usage](#using-the-probe-module)
|
|
33
|
-
+ [Example](#probe-module-example)
|
|
34
|
-
* [Dname module](#dname-module)
|
|
35
|
-
+ [Usage](#using-the-dname-module)
|
|
36
|
-
+ [Example](#dname-module-example)
|
|
37
|
-
|
|
38
|
-
## Introduction
|
|
39
|
-
|
|
40
|
-
If the shared `libknot.so` library isn't available in the library search path, it's
|
|
41
|
-
necessary to load the library first, e.g.:
|
|
42
|
-
|
|
43
|
-
```python3
|
|
44
|
-
import libknot
|
|
45
|
-
libknot.Knot("/usr/lib/libknot.so")
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Control module
|
|
49
|
-
|
|
50
|
-
Using this module it's possible to create scripts for efficient tasks that
|
|
51
|
-
would require complex shell scripts with multiple calls of `knotc`. For
|
|
52
|
-
communication with the daemon it uses the same mechanism as the `knotc` utility,
|
|
53
|
-
i.e. communication via a Unix socket.
|
|
54
|
-
|
|
55
|
-
The module API is stored in `libknot.control`.
|
|
56
|
-
|
|
57
|
-
### Using the Control module
|
|
58
|
-
|
|
59
|
-
The module usage consists of several steps:
|
|
60
|
-
|
|
61
|
-
* Initialization and connection to the daemon control socket.
|
|
62
|
-
* One or more control operations. An operation is called by sending a command
|
|
63
|
-
with optional data to the daemon. The operation result has to be received
|
|
64
|
-
afterwards.
|
|
65
|
-
* Closing the connection and deinitialization.
|
|
66
|
-
|
|
67
|
-
### Control module example
|
|
68
|
-
|
|
69
|
-
```python3
|
|
70
|
-
import json
|
|
71
|
-
import libknot.control
|
|
72
|
-
|
|
73
|
-
# Initialization
|
|
74
|
-
ctl = libknot.control.KnotCtl()
|
|
75
|
-
ctl.connect("/var/run/knot/knot.sock")
|
|
76
|
-
ctl.set_timeout(60)
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
# Operation without parameters
|
|
80
|
-
ctl.send_block(cmd="conf-begin")
|
|
81
|
-
resp = ctl.receive_block()
|
|
82
|
-
|
|
83
|
-
# Operation with parameters
|
|
84
|
-
ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test")
|
|
85
|
-
resp = ctl.receive_block()
|
|
86
|
-
|
|
87
|
-
ctl.send_block(cmd="conf-commit")
|
|
88
|
-
resp = ctl.receive_block()
|
|
89
|
-
|
|
90
|
-
# Operation with a result displayed in JSON format
|
|
91
|
-
ctl.send_block(cmd="conf-read", section="zone", item="domain")
|
|
92
|
-
resp = ctl.receive_block()
|
|
93
|
-
print(json.dumps(resp, indent=4))
|
|
94
|
-
except libknot.control.KnotCtlError as exc:
|
|
95
|
-
# Print libknot error
|
|
96
|
-
print(exc)
|
|
97
|
-
finally:
|
|
98
|
-
# Deinitialization
|
|
99
|
-
ctl.send(libknot.control.KnotCtlType.END)
|
|
100
|
-
ctl.close()
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
```python3
|
|
104
|
-
# List configured zones (including catalog member ones)
|
|
105
|
-
ctl.send_block(cmd="conf-list", flags="z")
|
|
106
|
-
resp = ctl.receive_block()
|
|
107
|
-
for zone in resp['zone']:
|
|
108
|
-
print(zone)
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Probe module
|
|
112
|
-
|
|
113
|
-
Using this module it's possible to receive traffic data from a running daemon with
|
|
114
|
-
active probe module.
|
|
115
|
-
|
|
116
|
-
The module API is stored in `libknot.probe`.
|
|
117
|
-
|
|
118
|
-
### Using the Probe module
|
|
119
|
-
|
|
120
|
-
The module usage consists of several steps:
|
|
121
|
-
|
|
122
|
-
* Initialization of one or more probe channels
|
|
123
|
-
* Periodical receiving of data units from the channels and data processing
|
|
124
|
-
|
|
125
|
-
### Probe module example
|
|
126
|
-
|
|
127
|
-
```python3
|
|
128
|
-
import libknot.probe
|
|
129
|
-
|
|
130
|
-
# Initialization of the first probe channel stored in `/run/knot`
|
|
131
|
-
probe = libknot.probe.KnotProbe("/run/knot", 1)
|
|
132
|
-
|
|
133
|
-
# Array for storing up to 8 data units
|
|
134
|
-
data = libknot.probe.KnotProbeDataArray(8)
|
|
135
|
-
while (True):
|
|
136
|
-
# Receiving data units with timeout of 1000 ms
|
|
137
|
-
if probe.consume(data, 1000) > 0:
|
|
138
|
-
# Printing received data units in the default format
|
|
139
|
-
for item in data:
|
|
140
|
-
print(item)
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Dname module
|
|
144
|
-
|
|
145
|
-
This module provides a few dname-related operations.
|
|
146
|
-
|
|
147
|
-
### Using the Dname module
|
|
148
|
-
|
|
149
|
-
The dname object is initialized from a string with textual dname.
|
|
150
|
-
Then the dname can be reformatted to wire format or back to textual format.
|
|
151
|
-
|
|
152
|
-
### Dname module example
|
|
153
|
-
|
|
154
|
-
```python3
|
|
155
|
-
import libknot.dname
|
|
156
|
-
|
|
157
|
-
dname1 = libknot.dname.KnotDname("knot-dns.cz")
|
|
158
|
-
print("%s: wire: %s size: %u" % (dname1.str(), dname1.wire(), dname1.size()))
|
|
159
|
-
|
|
160
|
-
dname2 = libknot.dname.KnotDname("e\\120ample.c\om.")
|
|
161
|
-
print("%s: wire: %s size: %u" % (dname2.str(), dname2.wire(), dname2.size()))
|
|
162
|
-
|
|
163
|
-
dname3 = libknot.dname.KnotDname(dname_wire=b'\x02cz\x00')
|
|
164
|
-
print("%s: wire: %s size: %u" % (dname3.str(), dname3.wire(), dname3.size()))
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
knot-dns.cz.: wire: b'\x08knot-dns\x02cz\x00' size: 13
|
|
169
|
-
example.com.: wire: b'\x07example\x03com\x00' size: 13
|
|
170
|
-
cz.: wire: b'\x02cz\x00' size: 4
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: libknot
|
|
3
|
-
Version: 3.2.9
|
|
4
|
-
Summary: Python bindings for libknot
|
|
5
|
-
Home-page: https://gitlab.nic.cz/knot/knot-dns
|
|
6
|
-
Author: Daniel Salzman
|
|
7
|
-
Author-email: daniel.salzman@nic.cz
|
|
8
|
-
License: GPL-3.0
|
|
9
|
-
Platform: UNKNOWN
|
|
10
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Intended Audience :: System Administrators
|
|
13
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Topic :: Internet :: Name Service (DNS)
|
|
16
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
-
Classifier: Topic :: System :: Systems Administration
|
|
18
|
-
Requires-Python: >=3.5
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
|
|
21
|
-
# Libknot API in Python
|
|
22
|
-
|
|
23
|
-
A Python interface for managing the Knot DNS daemon.
|
|
24
|
-
|
|
25
|
-
# Table of contents
|
|
26
|
-
|
|
27
|
-
* [Introduction](#introduction)
|
|
28
|
-
* [Control module](#control-module)
|
|
29
|
-
+ [Usage](#using-the-control-module)
|
|
30
|
-
+ [Example](#control-module-example)
|
|
31
|
-
* [Probe module](#probe-module)
|
|
32
|
-
+ [Usage](#using-the-probe-module)
|
|
33
|
-
+ [Example](#probe-module-example)
|
|
34
|
-
* [Dname module](#dname-module)
|
|
35
|
-
+ [Usage](#using-the-dname-module)
|
|
36
|
-
+ [Example](#dname-module-example)
|
|
37
|
-
|
|
38
|
-
## Introduction
|
|
39
|
-
|
|
40
|
-
If the shared `libknot.so` library isn't available in the library search path, it's
|
|
41
|
-
necessary to load the library first, e.g.:
|
|
42
|
-
|
|
43
|
-
```python3
|
|
44
|
-
import libknot
|
|
45
|
-
libknot.Knot("/usr/lib/libknot.so")
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Control module
|
|
49
|
-
|
|
50
|
-
Using this module it's possible to create scripts for efficient tasks that
|
|
51
|
-
would require complex shell scripts with multiple calls of `knotc`. For
|
|
52
|
-
communication with the daemon it uses the same mechanism as the `knotc` utility,
|
|
53
|
-
i.e. communication via a Unix socket.
|
|
54
|
-
|
|
55
|
-
The module API is stored in `libknot.control`.
|
|
56
|
-
|
|
57
|
-
### Using the Control module
|
|
58
|
-
|
|
59
|
-
The module usage consists of several steps:
|
|
60
|
-
|
|
61
|
-
* Initialization and connection to the daemon control socket.
|
|
62
|
-
* One or more control operations. An operation is called by sending a command
|
|
63
|
-
with optional data to the daemon. The operation result has to be received
|
|
64
|
-
afterwards.
|
|
65
|
-
* Closing the connection and deinitialization.
|
|
66
|
-
|
|
67
|
-
### Control module example
|
|
68
|
-
|
|
69
|
-
```python3
|
|
70
|
-
import json
|
|
71
|
-
import libknot.control
|
|
72
|
-
|
|
73
|
-
# Initialization
|
|
74
|
-
ctl = libknot.control.KnotCtl()
|
|
75
|
-
ctl.connect("/var/run/knot/knot.sock")
|
|
76
|
-
ctl.set_timeout(60)
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
# Operation without parameters
|
|
80
|
-
ctl.send_block(cmd="conf-begin")
|
|
81
|
-
resp = ctl.receive_block()
|
|
82
|
-
|
|
83
|
-
# Operation with parameters
|
|
84
|
-
ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test")
|
|
85
|
-
resp = ctl.receive_block()
|
|
86
|
-
|
|
87
|
-
ctl.send_block(cmd="conf-commit")
|
|
88
|
-
resp = ctl.receive_block()
|
|
89
|
-
|
|
90
|
-
# Operation with a result displayed in JSON format
|
|
91
|
-
ctl.send_block(cmd="conf-read", section="zone", item="domain")
|
|
92
|
-
resp = ctl.receive_block()
|
|
93
|
-
print(json.dumps(resp, indent=4))
|
|
94
|
-
except libknot.control.KnotCtlError as exc:
|
|
95
|
-
# Print libknot error
|
|
96
|
-
print(exc)
|
|
97
|
-
finally:
|
|
98
|
-
# Deinitialization
|
|
99
|
-
ctl.send(libknot.control.KnotCtlType.END)
|
|
100
|
-
ctl.close()
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
```python3
|
|
104
|
-
# List configured zones (including catalog member ones)
|
|
105
|
-
ctl.send_block(cmd="conf-list", flags="z")
|
|
106
|
-
resp = ctl.receive_block()
|
|
107
|
-
for zone in resp['zone']:
|
|
108
|
-
print(zone)
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Probe module
|
|
112
|
-
|
|
113
|
-
Using this module it's possible to receive traffic data from a running daemon with
|
|
114
|
-
active probe module.
|
|
115
|
-
|
|
116
|
-
The module API is stored in `libknot.probe`.
|
|
117
|
-
|
|
118
|
-
### Using the Probe module
|
|
119
|
-
|
|
120
|
-
The module usage consists of several steps:
|
|
121
|
-
|
|
122
|
-
* Initialization of one or more probe channels
|
|
123
|
-
* Periodical receiving of data units from the channels and data processing
|
|
124
|
-
|
|
125
|
-
### Probe module example
|
|
126
|
-
|
|
127
|
-
```python3
|
|
128
|
-
import libknot.probe
|
|
129
|
-
|
|
130
|
-
# Initialization of the first probe channel stored in `/run/knot`
|
|
131
|
-
probe = libknot.probe.KnotProbe("/run/knot", 1)
|
|
132
|
-
|
|
133
|
-
# Array for storing up to 8 data units
|
|
134
|
-
data = libknot.probe.KnotProbeDataArray(8)
|
|
135
|
-
while (True):
|
|
136
|
-
# Receiving data units with timeout of 1000 ms
|
|
137
|
-
if probe.consume(data, 1000) > 0:
|
|
138
|
-
# Printing received data units in the default format
|
|
139
|
-
for item in data:
|
|
140
|
-
print(item)
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Dname module
|
|
144
|
-
|
|
145
|
-
This module provides a few dname-related operations.
|
|
146
|
-
|
|
147
|
-
### Using the Dname module
|
|
148
|
-
|
|
149
|
-
The dname object is initialized from a string with textual dname.
|
|
150
|
-
Then the dname can be reformatted to wire format or back to textual format.
|
|
151
|
-
|
|
152
|
-
### Dname module example
|
|
153
|
-
|
|
154
|
-
```python3
|
|
155
|
-
import libknot.dname
|
|
156
|
-
|
|
157
|
-
dname1 = libknot.dname.KnotDname("knot-dns.cz")
|
|
158
|
-
print("%s: wire: %s size: %u" % (dname1.str(), dname1.wire(), dname1.size()))
|
|
159
|
-
|
|
160
|
-
dname2 = libknot.dname.KnotDname("e\\120ample.c\om.")
|
|
161
|
-
print("%s: wire: %s size: %u" % (dname2.str(), dname2.wire(), dname2.size()))
|
|
162
|
-
|
|
163
|
-
dname3 = libknot.dname.KnotDname(dname_wire=b'\x02cz\x00')
|
|
164
|
-
print("%s: wire: %s size: %u" % (dname3.str(), dname3.wire(), dname3.size()))
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
knot-dns.cz.: wire: b'\x08knot-dns\x02cz\x00' size: 13
|
|
169
|
-
example.com.: wire: b'\x07example\x03com\x00' size: 13
|
|
170
|
-
cz.: wire: b'\x02cz\x00' size: 4
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|