somestuff-dnsstuff 0.2.1__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.
@@ -0,0 +1,180 @@
1
+ /**/.gtfs_cache
2
+ /*.local
3
+ .claude
4
+
5
+ /*gguf*
6
+
7
+ /docker-config
8
+ /docker_build_local.log
9
+
10
+ /ms?hit
11
+ *mstest*py
12
+ *_test.py
13
+ /umqtt
14
+ .idea/
15
+ /upydev_.config
16
+ *.local.*
17
+ /scripts/logdir/
18
+
19
+
20
+ # Byte-compiled / optimized / DLL files
21
+ __pycache__/
22
+ *.py[cod]
23
+ *$py.class
24
+
25
+ # C extensions
26
+ *.so
27
+
28
+ # Distribution / packaging
29
+ .Python
30
+ build/
31
+ develop-eggs/
32
+ dist/
33
+ downloads/
34
+ eggs/
35
+ .eggs/
36
+ lib/
37
+ lib64/
38
+ parts/
39
+ sdist/
40
+ var/
41
+ wheels/
42
+ share/python-wheels/
43
+ *.egg-info/
44
+ .installed.cfg
45
+ *.egg
46
+ MANIFEST
47
+
48
+ # PyInstaller
49
+ # Usually these files are written by a python script from a template
50
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
51
+ *.manifest
52
+ *.spec
53
+
54
+ # Installer logs
55
+ pip-log.txt
56
+ pip-delete-this-directory.txt
57
+
58
+ # Unit test / coverage reports
59
+ htmlcov/
60
+ .tox/
61
+ .nox/
62
+ .coverage
63
+ .coverage.*
64
+ .cache
65
+ nosetests.xml
66
+ coverage.xml
67
+ *.cover
68
+ *.py,cover
69
+ .hypothesis/
70
+ .pytest_cache/
71
+ cover/
72
+
73
+ # Translations
74
+ *.mo
75
+ *.pot
76
+
77
+ # Django stuff:
78
+ *.log
79
+ local_settings.py
80
+ db.sqlite3
81
+ db.sqlite3-journal
82
+
83
+ # Flask stuff:
84
+ instance/
85
+ .webassets-cache
86
+
87
+ # Scrapy stuff:
88
+ .scrapy
89
+
90
+ # Sphinx documentation
91
+ docs/_build/
92
+
93
+ # PyBuilder
94
+ .pybuilder/
95
+ target/
96
+
97
+ # Jupyter Notebook
98
+ .ipynb_checkpoints
99
+
100
+ # IPython
101
+ profile_default/
102
+ ipython_config.py
103
+
104
+ # pyenv
105
+ # For a library or package, you might want to ignore these files since the code is
106
+ # intended to run in multiple environments; otherwise, check them in:
107
+ # .python-version
108
+
109
+ # pipenv
110
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
111
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
112
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
113
+ # install all needed dependencies.
114
+ #Pipfile.lock
115
+
116
+ # poetry
117
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
118
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
119
+ # commonly ignored for libraries.
120
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
121
+ #poetry.lock
122
+
123
+ # pdm
124
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
125
+ #pdm.lock
126
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
127
+ # in version control.
128
+ # https://pdm.fming.dev/#use-with-ide
129
+ .pdm.toml
130
+
131
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
132
+ __pypackages__/
133
+
134
+ # Celery stuff
135
+ celerybeat-schedule
136
+ celerybeat.pid
137
+
138
+ # SageMath parsed files
139
+ *.sage.py
140
+
141
+ # Environments
142
+ .env
143
+ .venv
144
+ env/
145
+ venv/
146
+ ENV/
147
+ env.bak/
148
+ venv.bak/
149
+
150
+ # Spyder project settings
151
+ .spyderproject
152
+ .spyproject
153
+
154
+ # Rope project settings
155
+ .ropeproject
156
+
157
+ # mkdocs documentation
158
+ /site
159
+
160
+ # mypy
161
+ .mypy_cache/
162
+ .dmypy.json
163
+ dmypy.json
164
+
165
+ # Pyre type checker
166
+ .pyre/
167
+
168
+ # pytype static type analyzer
169
+ .pytype/
170
+
171
+ # Cython debug symbols
172
+ cython_debug/
173
+
174
+ # PyCharm
175
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
176
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
177
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
178
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
179
+ #.idea/
180
+
@@ -0,0 +1,163 @@
1
+ GNU Lesser General Public License
2
+ =================================
3
+
4
+ _Version 3, 29 June 2007_
5
+ _Copyright © 2007 Free Software Foundation, Inc. &lt;<http://fsf.org/>&gt;_
6
+
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+
11
+ This version of the GNU Lesser General Public License incorporates
12
+ the terms and conditions of version 3 of the GNU General Public
13
+ License, supplemented by the additional permissions listed below.
14
+
15
+ ### 0. Additional Definitions
16
+
17
+ As used herein, “this License” refers to version 3 of the GNU Lesser
18
+ General Public License, and the “GNU GPL” refers to version 3 of the GNU
19
+ General Public License.
20
+
21
+ “The Library” refers to a covered work governed by this License,
22
+ other than an Application or a Combined Work as defined below.
23
+
24
+ An “Application” is any work that makes use of an interface provided
25
+ by the Library, but which is not otherwise based on the Library.
26
+ Defining a subclass of a class defined by the Library is deemed a mode
27
+ of using an interface provided by the Library.
28
+
29
+ A “Combined Work” is a work produced by combining or linking an
30
+ Application with the Library. The particular version of the Library
31
+ with which the Combined Work was made is also called the “Linked
32
+ Version”.
33
+
34
+ The “Minimal Corresponding Source” for a Combined Work means the
35
+ Corresponding Source for the Combined Work, excluding any source code
36
+ for portions of the Combined Work that, considered in isolation, are
37
+ based on the Application, and not on the Linked Version.
38
+
39
+ The “Corresponding Application Code” for a Combined Work means the
40
+ object code and/or source code for the Application, including any data
41
+ and utility programs needed for reproducing the Combined Work from the
42
+ Application, but excluding the System Libraries of the Combined Work.
43
+
44
+ ### 1. Exception to Section 3 of the GNU GPL
45
+
46
+ You may convey a covered work under sections 3 and 4 of this License
47
+ without being bound by section 3 of the GNU GPL.
48
+
49
+ ### 2. Conveying Modified Versions
50
+
51
+ If you modify a copy of the Library, and, in your modifications, a
52
+ facility refers to a function or data to be supplied by an Application
53
+ that uses the facility (other than as an argument passed when the
54
+ facility is invoked), then you may convey a copy of the modified
55
+ version:
56
+
57
+ * **a)** under this License, provided that you make a good faith effort to
58
+ ensure that, in the event an Application does not supply the
59
+ function or data, the facility still operates, and performs
60
+ whatever part of its purpose remains meaningful, or
61
+
62
+ * **b)** under the GNU GPL, with none of the additional permissions of
63
+ this License applicable to that copy.
64
+
65
+ ### 3. Object Code Incorporating Material from Library Header Files
66
+
67
+ The object code form of an Application may incorporate material from
68
+ a header file that is part of the Library. You may convey such object
69
+ code under terms of your choice, provided that, if the incorporated
70
+ material is not limited to numerical parameters, data structure
71
+ layouts and accessors, or small macros, inline functions and templates
72
+ (ten or fewer lines in length), you do both of the following:
73
+
74
+ * **a)** Give prominent notice with each copy of the object code that the
75
+ Library is used in it and that the Library and its use are
76
+ covered by this License.
77
+ * **b)** Accompany the object code with a copy of the GNU GPL and this license
78
+ document.
79
+
80
+ ### 4. Combined Works
81
+
82
+ You may convey a Combined Work under terms of your choice that,
83
+ taken together, effectively do not restrict modification of the
84
+ portions of the Library contained in the Combined Work and reverse
85
+ engineering for debugging such modifications, if you also do each of
86
+ the following:
87
+
88
+ * **a)** Give prominent notice with each copy of the Combined Work that
89
+ the Library is used in it and that the Library and its use are
90
+ covered by this License.
91
+
92
+ * **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
93
+ document.
94
+
95
+ * **c)** For a Combined Work that displays copyright notices during
96
+ execution, include the copyright notice for the Library among
97
+ these notices, as well as a reference directing the user to the
98
+ copies of the GNU GPL and this license document.
99
+
100
+ * **d)** Do one of the following:
101
+ - **0)** Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+ - **1)** Use a suitable shared library mechanism for linking with the
109
+ Library. A suitable mechanism is one that **(a)** uses at run time
110
+ a copy of the Library already present on the user's computer
111
+ system, and **(b)** will operate properly with a modified version
112
+ of the Library that is interface-compatible with the Linked
113
+ Version.
114
+
115
+ * **e)** Provide Installation Information, but only if you would otherwise
116
+ be required to provide such information under section 6 of the
117
+ GNU GPL, and only to the extent that such information is
118
+ necessary to install and execute a modified version of the
119
+ Combined Work produced by recombining or relinking the
120
+ Application with a modified version of the Linked Version. (If
121
+ you use option **4d0**, the Installation Information must accompany
122
+ the Minimal Corresponding Source and Corresponding Application
123
+ Code. If you use option **4d1**, you must provide the Installation
124
+ Information in the manner specified by section 6 of the GNU GPL
125
+ for conveying Corresponding Source.)
126
+
127
+ ### 5. Combined Libraries
128
+
129
+ You may place library facilities that are a work based on the
130
+ Library side by side in a single library together with other library
131
+ facilities that are not Applications and are not covered by this
132
+ License, and convey such a combined library under terms of your
133
+ choice, if you do both of the following:
134
+
135
+ * **a)** Accompany the combined library with a copy of the same work based
136
+ on the Library, uncombined with any other library facilities,
137
+ conveyed under the terms of this License.
138
+ * **b)** Give prominent notice with the combined library that part of it
139
+ is a work based on the Library, and explaining where to find the
140
+ accompanying uncombined form of the same work.
141
+
142
+ ### 6. Revised Versions of the GNU Lesser General Public License
143
+
144
+ The Free Software Foundation may publish revised and/or new versions
145
+ of the GNU Lesser General Public License from time to time. Such new
146
+ versions will be similar in spirit to the present version, but may
147
+ differ in detail to address new problems or concerns.
148
+
149
+ Each version is given a distinguishing version number. If the
150
+ Library as you received it specifies that a certain numbered version
151
+ of the GNU Lesser General Public License “or any later version”
152
+ applies to it, you have the option of following the terms and
153
+ conditions either of that published version or of any later version
154
+ published by the Free Software Foundation. If the Library as you
155
+ received it does not specify a version number of the GNU Lesser
156
+ General Public License, you may choose any version of the GNU Lesser
157
+ General Public License ever published by the Free Software Foundation.
158
+
159
+ If the Library as you received it specifies that a proxy can decide
160
+ whether future versions of the GNU Lesser General Public License shall
161
+ apply, that proxy's public statement of acceptance of any version is
162
+ permanent authorization for you to choose that version for the
163
+ Library.
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.5
2
+ Name: somestuff-dnsstuff
3
+ Version: 0.2.1
4
+ Summary: DNS utilities: SPF crawler → ipset updater, Microsoft 365 21Vianet IP sync, mDNS responder diagnostics
5
+ Project-URL: Homepage, https://github.com/vroomfondel/somestuff
6
+ Project-URL: Repository, https://github.com/vroomfondel/somestuff
7
+ Project-URL: Issues, https://github.com/vroomfondel/somestuff/issues
8
+ Author-email: Henning Thieß <ht@xomox.cc>
9
+ License-File: LICENSE.md
10
+ Keywords: 21vianet,allowlist,dns,ipset,mdns,netfilter,pyroute2,smtp,spf
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Internet :: Name Service (DNS)
19
+ Classifier: Topic :: System :: Networking
20
+ Classifier: Topic :: System :: Networking :: Firewalls
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.13
23
+ Requires-Dist: dnspython>=2.9
24
+ Requires-Dist: loguru>=0.7.3
25
+ Requires-Dist: pyroute2>=0.9
26
+ Requires-Dist: tabulate>=0.10
27
+ Description-Content-Type: text/markdown
28
+
29
+ # dnsstuff
30
+
31
+ DNS and network diagnostics for mail relays and LANs: an SPF crawler that feeds a
32
+ Linux `ipset`, a Microsoft 365 21Vianet IP-range updater, and an mDNS resolver that
33
+ shows which host actually answered.
34
+
35
+ ## Modules
36
+
37
+ - **`spf_ipset_updater.py`** — recursively resolves the SPF records of the given
38
+ domains (`include:`, `a`, `mx`, `ip4`, redirects), collects every IPv4 address and
39
+ network and atomically swaps the result into a kernel `ipset` via netlink
40
+ (`pyroute2`). Meant for SMTP allowlists on relay hosts.
41
+ - **`update_21vianet_ips.py`** — polls the Microsoft 365 endpoint API for the
42
+ 21Vianet (China) Exchange Online ranges, caches the version and updates two
43
+ ipsets: all Exchange IPv4 networks and the SMTP-only (port 25) subset.
44
+ - **`mdns_who.py`** — sends an mDNS query for a `.local` name itself and reports
45
+ every responder: source IP, advertised A records, TTL and cache-flush bit.
46
+ Flags proxied, cached or reflected replies (source IP ≠ advertised IP, more
47
+ than one responder). `--unicast` adds a system-resolver lookup to surface a
48
+ stale router DHCP lease.
49
+
50
+ Logging (loguru, with an intercept for stdlib `logging` from `dnspython`,
51
+ `pyroute2`, `urllib`) and the startup banner are shared via `somestuff.dnsstuff`.
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ pip install somestuff-dnsstuff
57
+ ```
58
+
59
+ `somestuff` is a PEP 420 namespace; the package is imported as
60
+ `somestuff.dnsstuff` and shares the namespace with the other `somestuff-*`
61
+ distributions.
62
+
63
+ ## Usage
64
+
65
+ Console scripts and module invocation are equivalent:
66
+
67
+ ```bash
68
+ spf-ipset-updater example.com mail.example.net --ipset-name smtpallowlist
69
+ python3 -m somestuff.dnsstuff.spf_ipset_updater example.com --dry-run -v
70
+
71
+ update-21vianet-ips --ipset-name-all 21vianet_exchange --ipset-name-smtp 21vianet_smtp
72
+ python3 -m somestuff.dnsstuff.update_21vianet_ips --force --dry-run
73
+
74
+ mdns-who printer.local
75
+ python3 -m somestuff.dnsstuff.mdns_who printer --timeout 3 --unicast --iface 192.0.2.5
76
+ ```
77
+
78
+ Common flags: `--dry-run` populates the ipset but skips the atomic swap,
79
+ `--no-comment` disables the ipset comment extension, `-v` enables DEBUG logging.
80
+ `update-21vianet-ips --help` lists the cache directory and API timeout options.
81
+
82
+ Cron example for the 21Vianet updater (daily at 03:00):
83
+
84
+ ```
85
+ 0 3 * * * update-21vianet-ips 2>&1 | logger -t 21vianet
86
+ ```
87
+
88
+ ### Library
89
+
90
+ ```python
91
+ from somestuff.dnsstuff import configure_logging
92
+ from somestuff.dnsstuff.spf_ipset_updater import get_spf_records
93
+
94
+ configure_logging(verbose=True)
95
+ ```
96
+
97
+ ## Privileges
98
+
99
+ - `spf-ipset-updater` and `update-21vianet-ips` modify kernel ipsets over netlink
100
+ and need `CAP_NET_ADMIN` (in practice: root).
101
+ - `mdns-who` binds a UDP socket on port 5353 and joins the mDNS multicast group;
102
+ on most systems this works unprivileged unless another mDNS daemon holds the
103
+ port exclusively.
104
+
105
+ ## Notes
106
+
107
+ - Requires: `dnspython`, `pyroute2`, `loguru`, `tabulate`. Linux only (netlink ipsets).
108
+ - Licensed under the LGPL, see `LICENSE.md` in the repository root.
@@ -0,0 +1,80 @@
1
+ # dnsstuff
2
+
3
+ DNS and network diagnostics for mail relays and LANs: an SPF crawler that feeds a
4
+ Linux `ipset`, a Microsoft 365 21Vianet IP-range updater, and an mDNS resolver that
5
+ shows which host actually answered.
6
+
7
+ ## Modules
8
+
9
+ - **`spf_ipset_updater.py`** — recursively resolves the SPF records of the given
10
+ domains (`include:`, `a`, `mx`, `ip4`, redirects), collects every IPv4 address and
11
+ network and atomically swaps the result into a kernel `ipset` via netlink
12
+ (`pyroute2`). Meant for SMTP allowlists on relay hosts.
13
+ - **`update_21vianet_ips.py`** — polls the Microsoft 365 endpoint API for the
14
+ 21Vianet (China) Exchange Online ranges, caches the version and updates two
15
+ ipsets: all Exchange IPv4 networks and the SMTP-only (port 25) subset.
16
+ - **`mdns_who.py`** — sends an mDNS query for a `.local` name itself and reports
17
+ every responder: source IP, advertised A records, TTL and cache-flush bit.
18
+ Flags proxied, cached or reflected replies (source IP ≠ advertised IP, more
19
+ than one responder). `--unicast` adds a system-resolver lookup to surface a
20
+ stale router DHCP lease.
21
+
22
+ Logging (loguru, with an intercept for stdlib `logging` from `dnspython`,
23
+ `pyroute2`, `urllib`) and the startup banner are shared via `somestuff.dnsstuff`.
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install somestuff-dnsstuff
29
+ ```
30
+
31
+ `somestuff` is a PEP 420 namespace; the package is imported as
32
+ `somestuff.dnsstuff` and shares the namespace with the other `somestuff-*`
33
+ distributions.
34
+
35
+ ## Usage
36
+
37
+ Console scripts and module invocation are equivalent:
38
+
39
+ ```bash
40
+ spf-ipset-updater example.com mail.example.net --ipset-name smtpallowlist
41
+ python3 -m somestuff.dnsstuff.spf_ipset_updater example.com --dry-run -v
42
+
43
+ update-21vianet-ips --ipset-name-all 21vianet_exchange --ipset-name-smtp 21vianet_smtp
44
+ python3 -m somestuff.dnsstuff.update_21vianet_ips --force --dry-run
45
+
46
+ mdns-who printer.local
47
+ python3 -m somestuff.dnsstuff.mdns_who printer --timeout 3 --unicast --iface 192.0.2.5
48
+ ```
49
+
50
+ Common flags: `--dry-run` populates the ipset but skips the atomic swap,
51
+ `--no-comment` disables the ipset comment extension, `-v` enables DEBUG logging.
52
+ `update-21vianet-ips --help` lists the cache directory and API timeout options.
53
+
54
+ Cron example for the 21Vianet updater (daily at 03:00):
55
+
56
+ ```
57
+ 0 3 * * * update-21vianet-ips 2>&1 | logger -t 21vianet
58
+ ```
59
+
60
+ ### Library
61
+
62
+ ```python
63
+ from somestuff.dnsstuff import configure_logging
64
+ from somestuff.dnsstuff.spf_ipset_updater import get_spf_records
65
+
66
+ configure_logging(verbose=True)
67
+ ```
68
+
69
+ ## Privileges
70
+
71
+ - `spf-ipset-updater` and `update-21vianet-ips` modify kernel ipsets over netlink
72
+ and need `CAP_NET_ADMIN` (in practice: root).
73
+ - `mdns-who` binds a UDP socket on port 5353 and joins the mDNS multicast group;
74
+ on most systems this works unprivileged unless another mDNS daemon holds the
75
+ port exclusively.
76
+
77
+ ## Notes
78
+
79
+ - Requires: `dnspython`, `pyroute2`, `loguru`, `tabulate`. Linux only (netlink ipsets).
80
+ - Licensed under the LGPL, see `LICENSE.md` in the repository root.
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "somestuff-dnsstuff"
7
+ dynamic = ["version"]
8
+ description = "DNS utilities: SPF crawler → ipset updater, Microsoft 365 21Vianet IP sync, mDNS responder diagnostics"
9
+ readme = "README.md"
10
+ requires-python = ">=3.13"
11
+ authors = [{ name = "Henning Thieß", email = "ht@xomox.cc" }]
12
+ license-files = ["LICENSE.md"]
13
+ keywords = ["dns", "spf", "ipset", "mdns", "netfilter", "smtp", "allowlist", "21vianet", "pyroute2"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: System Administrators",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Programming Language :: Python :: 3.14",
20
+ "Topic :: System :: Networking",
21
+ "Topic :: Internet :: Name Service (DNS)",
22
+ "Topic :: System :: Networking :: Firewalls",
23
+ "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
24
+ "Operating System :: POSIX :: Linux",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = [
28
+ "loguru>=0.7.3",
29
+ "dnspython>=2.9",
30
+ "pyroute2>=0.9",
31
+ "tabulate>=0.10",
32
+ ]
33
+
34
+ [project.scripts]
35
+ spf-ipset-updater = "somestuff.dnsstuff.spf_ipset_updater:main"
36
+ mdns-who = "somestuff.dnsstuff.mdns_who:main"
37
+ update-21vianet-ips = "somestuff.dnsstuff.update_21vianet_ips:main"
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/vroomfondel/somestuff"
41
+ Repository = "https://github.com/vroomfondel/somestuff"
42
+ Issues = "https://github.com/vroomfondel/somestuff/issues"
43
+
44
+ [tool.hatch.version]
45
+ path = "somestuff/dnsstuff/__init__.py"
46
+
47
+ # Build-level selection governs sdist AND wheel; a wheel-only `packages` leaves the sdist unscoped.
48
+ [tool.hatch.build]
49
+ packages = ["somestuff"]
50
+ exclude = ["**/__pycache__", "**/*.pyc", "**/*.local.*"]
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ exclude = ["**/*.local.*", "**/README.md", "**/*_deployment.yml", "**/*.example", "**/*.example.yaml"]
@@ -0,0 +1,80 @@
1
+ # dnsstuff
2
+
3
+ DNS and network diagnostics for mail relays and LANs: an SPF crawler that feeds a
4
+ Linux `ipset`, a Microsoft 365 21Vianet IP-range updater, and an mDNS resolver that
5
+ shows which host actually answered.
6
+
7
+ ## Modules
8
+
9
+ - **`spf_ipset_updater.py`** — recursively resolves the SPF records of the given
10
+ domains (`include:`, `a`, `mx`, `ip4`, redirects), collects every IPv4 address and
11
+ network and atomically swaps the result into a kernel `ipset` via netlink
12
+ (`pyroute2`). Meant for SMTP allowlists on relay hosts.
13
+ - **`update_21vianet_ips.py`** — polls the Microsoft 365 endpoint API for the
14
+ 21Vianet (China) Exchange Online ranges, caches the version and updates two
15
+ ipsets: all Exchange IPv4 networks and the SMTP-only (port 25) subset.
16
+ - **`mdns_who.py`** — sends an mDNS query for a `.local` name itself and reports
17
+ every responder: source IP, advertised A records, TTL and cache-flush bit.
18
+ Flags proxied, cached or reflected replies (source IP ≠ advertised IP, more
19
+ than one responder). `--unicast` adds a system-resolver lookup to surface a
20
+ stale router DHCP lease.
21
+
22
+ Logging (loguru, with an intercept for stdlib `logging` from `dnspython`,
23
+ `pyroute2`, `urllib`) and the startup banner are shared via `somestuff.dnsstuff`.
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install somestuff-dnsstuff
29
+ ```
30
+
31
+ `somestuff` is a PEP 420 namespace; the package is imported as
32
+ `somestuff.dnsstuff` and shares the namespace with the other `somestuff-*`
33
+ distributions.
34
+
35
+ ## Usage
36
+
37
+ Console scripts and module invocation are equivalent:
38
+
39
+ ```bash
40
+ spf-ipset-updater example.com mail.example.net --ipset-name smtpallowlist
41
+ python3 -m somestuff.dnsstuff.spf_ipset_updater example.com --dry-run -v
42
+
43
+ update-21vianet-ips --ipset-name-all 21vianet_exchange --ipset-name-smtp 21vianet_smtp
44
+ python3 -m somestuff.dnsstuff.update_21vianet_ips --force --dry-run
45
+
46
+ mdns-who printer.local
47
+ python3 -m somestuff.dnsstuff.mdns_who printer --timeout 3 --unicast --iface 192.0.2.5
48
+ ```
49
+
50
+ Common flags: `--dry-run` populates the ipset but skips the atomic swap,
51
+ `--no-comment` disables the ipset comment extension, `-v` enables DEBUG logging.
52
+ `update-21vianet-ips --help` lists the cache directory and API timeout options.
53
+
54
+ Cron example for the 21Vianet updater (daily at 03:00):
55
+
56
+ ```
57
+ 0 3 * * * update-21vianet-ips 2>&1 | logger -t 21vianet
58
+ ```
59
+
60
+ ### Library
61
+
62
+ ```python
63
+ from somestuff.dnsstuff import configure_logging
64
+ from somestuff.dnsstuff.spf_ipset_updater import get_spf_records
65
+
66
+ configure_logging(verbose=True)
67
+ ```
68
+
69
+ ## Privileges
70
+
71
+ - `spf-ipset-updater` and `update-21vianet-ips` modify kernel ipsets over netlink
72
+ and need `CAP_NET_ADMIN` (in practice: root).
73
+ - `mdns-who` binds a UDP socket on port 5353 and joins the mDNS multicast group;
74
+ on most systems this works unprivileged unless another mDNS daemon holds the
75
+ port exclusively.
76
+
77
+ ## Notes
78
+
79
+ - Requires: `dnspython`, `pyroute2`, `loguru`, `tabulate`. Linux only (netlink ipsets).
80
+ - Licensed under the LGPL, see `LICENSE.md` in the repository root.