macblock 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.
Files changed (40) hide show
  1. macblock-0.2.1/LICENSE +21 -0
  2. macblock-0.2.1/PKG-INFO +195 -0
  3. macblock-0.2.1/README.md +163 -0
  4. macblock-0.2.1/pyproject.toml +68 -0
  5. macblock-0.2.1/setup.cfg +4 -0
  6. macblock-0.2.1/src/macblock/__init__.py +8 -0
  7. macblock-0.2.1/src/macblock/__main__.py +4 -0
  8. macblock-0.2.1/src/macblock/blocklists.py +260 -0
  9. macblock-0.2.1/src/macblock/cli.py +323 -0
  10. macblock-0.2.1/src/macblock/colors.py +62 -0
  11. macblock-0.2.1/src/macblock/constants.py +81 -0
  12. macblock-0.2.1/src/macblock/control.py +266 -0
  13. macblock-0.2.1/src/macblock/daemon.py +449 -0
  14. macblock-0.2.1/src/macblock/dns_test.py +165 -0
  15. macblock-0.2.1/src/macblock/dnsmasq.py +36 -0
  16. macblock-0.2.1/src/macblock/doctor.py +338 -0
  17. macblock-0.2.1/src/macblock/errors.py +10 -0
  18. macblock-0.2.1/src/macblock/exec.py +39 -0
  19. macblock-0.2.1/src/macblock/fs.py +19 -0
  20. macblock-0.2.1/src/macblock/help.py +447 -0
  21. macblock-0.2.1/src/macblock/install.py +677 -0
  22. macblock-0.2.1/src/macblock/launchd.py +44 -0
  23. macblock-0.2.1/src/macblock/lists.py +98 -0
  24. macblock-0.2.1/src/macblock/logs.py +140 -0
  25. macblock-0.2.1/src/macblock/platform.py +15 -0
  26. macblock-0.2.1/src/macblock/resolvers.py +76 -0
  27. macblock-0.2.1/src/macblock/state.py +146 -0
  28. macblock-0.2.1/src/macblock/status.py +145 -0
  29. macblock-0.2.1/src/macblock/system_dns.py +205 -0
  30. macblock-0.2.1/src/macblock/ui.py +308 -0
  31. macblock-0.2.1/src/macblock/users.py +75 -0
  32. macblock-0.2.1/src/macblock.egg-info/PKG-INFO +195 -0
  33. macblock-0.2.1/src/macblock.egg-info/SOURCES.txt +38 -0
  34. macblock-0.2.1/src/macblock.egg-info/dependency_links.txt +1 -0
  35. macblock-0.2.1/src/macblock.egg-info/entry_points.txt +2 -0
  36. macblock-0.2.1/src/macblock.egg-info/requires.txt +6 -0
  37. macblock-0.2.1/src/macblock.egg-info/top_level.txt +1 -0
  38. macblock-0.2.1/tests/test_blocklists.py +22 -0
  39. macblock-0.2.1/tests/test_cli.py +51 -0
  40. macblock-0.2.1/tests/test_dns_test.py +45 -0
macblock-0.2.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 macblock contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.4
2
+ Name: macblock
3
+ Version: 0.2.1
4
+ Summary: Local DNS sinkhole for macOS using dnsmasq
5
+ Author: macbblock contributiers
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/SpyicyDev/macblock
8
+ Project-URL: Repository, https://github.com/SpyicyDev/macblock
9
+ Project-URL: Issues, https://github.com/SpyicyDev/macblock/issues
10
+ Project-URL: Changelog, https://github.com/SpyicyDev/macblock/blob/main/CHANGELOG.md
11
+ Keywords: dns,ad-blocker,dnsmasq,macos
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Internet :: Name Service (DNS)
22
+ Classifier: Topic :: Security
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: dev
27
+ Requires-Dist: ruff>=0.8.0; extra == "dev"
28
+ Requires-Dist: pyright>=1.1.390; extra == "dev"
29
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # macblock
34
+
35
+ [![CI](https://github.com/SpyicyDev/macblock/actions/workflows/ci.yml/badge.svg)](https://github.com/SpyicyDev/macblock/actions/workflows/ci.yml)
36
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
37
+
38
+ Local DNS sinkhole for macOS using `dnsmasq` on `127.0.0.1:53`, with automatic system DNS configuration and split-DNS preservation.
39
+
40
+ ## Vibe-coding disclaimer
41
+
42
+ Most of this project was vibe-coded with careful code review and analysis of what the daemon touches. Every effort was made to ensure that the services here are using root as little as possible. If you find any holes I missed, please open an issue or a PR!
43
+
44
+ ## Features
45
+
46
+ - Blocks ads, trackers, and malware at the DNS level
47
+ - Automatically configures DNS for managed network services
48
+ - Preserves VPN/corporate split-DNS routing
49
+ - Pause/resume with automatic timers
50
+ - Whitelist/blacklist management
51
+ - Multiple blocklist sources (StevenBlack, HaGeZi, OISD) or a custom URL
52
+
53
+ ## Install
54
+
55
+ ### Via Homebrew (recommended)
56
+
57
+ ```bash
58
+ brew install SpyicyDev/formulae/macblock
59
+ ```
60
+
61
+ Or, if you prefer adding the tap explicitly:
62
+
63
+ ```bash
64
+ brew tap SpyicyDev/formulae
65
+ brew install macblock
66
+ ```
67
+
68
+ ### Quick start
69
+
70
+ `macblock` performs privileged operations (launchd + system DNS changes). You can run root-required commands with `sudo`, or omit it and let `macblock` auto-elevate.
71
+
72
+ ```bash
73
+ sudo macblock install
74
+ sudo macblock enable
75
+ macblock status
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ```text
81
+ macblock <command> [flags]
82
+ ```
83
+
84
+ ### Global flags
85
+
86
+ - `-h`, `--help`: show help for a command
87
+ - `-V`, `--version`: show version
88
+
89
+ ### Commands
90
+
91
+ Status & diagnostics:
92
+
93
+ - `macblock status`: show current status
94
+ - `macblock doctor`: run diagnostics and health checks
95
+ - `macblock logs [--component daemon|dnsmasq] [--lines N] [--follow] [--stderr]`: view logs
96
+ - `macblock test <domain>`: test resolution against the local resolver
97
+
98
+ Control:
99
+
100
+ - `sudo macblock enable`: enable DNS blocking
101
+ - `sudo macblock disable`: disable DNS blocking
102
+ - `sudo macblock pause <duration>`: temporarily disable (e.g. `10m`, `2h`, `1d`)
103
+ - `sudo macblock resume`: resume blocking
104
+
105
+ Installation & updates:
106
+
107
+ - `sudo macblock install [--force] [--skip-update]`: install system integration
108
+ - `sudo macblock uninstall [--force]`: remove system integration
109
+ - `sudo macblock update [--source <name|url>] [--sha256 <hash>]`: download + compile blocklist and reload dnsmasq
110
+
111
+ Configuration:
112
+
113
+ - `macblock sources list`: list available blocklist sources
114
+ - `sudo macblock sources set <source>`: set blocklist source
115
+ - `macblock allow list`: list whitelisted domains
116
+ - `sudo macblock allow add|remove <domain>`: manage whitelist
117
+ - `macblock deny list`: list blacklisted domains
118
+ - `sudo macblock deny add|remove <domain>`: manage blacklist
119
+
120
+ Tip: `macblock <command> --help` shows per-command usage.
121
+
122
+ ## How it works
123
+
124
+ 1. `dnsmasq` listens on `127.0.0.1:53` and serves DNS.
125
+ 2. The macblock daemon watches for network changes and reconciles state.
126
+ 3. When enabled, macblock sets DNS to `127.0.0.1` for a set of managed macOS network services (it intentionally skips VPN-ish services/devices).
127
+ 4. macblock generates dnsmasq upstream routing from `scutil --dns` so domain-specific resolvers (VPN/corporate split-DNS) keep working.
128
+ 5. Blocked domains are answered as `NXDOMAIN` via dnsmasq rules.
129
+
130
+ Note: Encrypted DNS (DoH/DoT) can bypass macblock; `macblock doctor` warns if detected.
131
+
132
+ ## `macblock test` behavior
133
+
134
+ `macblock test <domain>` runs `dig` against `127.0.0.1:53` and uses the compiled block rules to interpret `NXDOMAIN`:
135
+
136
+ - If the domain matches a block rule, `NXDOMAIN` is reported as **BLOCKED**.
137
+ - If the domain does not match a block rule, `NXDOMAIN` is reported as **does not exist**.
138
+
139
+ If you don't have `dig`, install it with:
140
+
141
+ ```bash
142
+ brew install bind
143
+ ```
144
+
145
+ ## Uninstall
146
+
147
+ See `docs/UNINSTALL.md`.
148
+
149
+ Quick version:
150
+
151
+ ```bash
152
+ sudo macblock uninstall
153
+ brew uninstall macblock dnsmasq
154
+ ```
155
+
156
+ ## Troubleshooting
157
+
158
+ - Run `macblock doctor` first.
159
+ - View logs: `macblock logs --component daemon` or `macblock logs --component dnsmasq --stderr`.
160
+ - Verify DNS state: `scutil --dns` (macblock uses this to preserve split DNS).
161
+ - Port conflict on `:53`: `sudo lsof -i :53 -P -n`.
162
+
163
+ ## Attribution
164
+
165
+ macblock can download third-party blocklists from:
166
+
167
+ - StevenBlack hosts: https://github.com/StevenBlack/hosts
168
+ - HaGeZi DNS blocklists: https://github.com/hagezi/dns-blocklists
169
+ - OISD: https://oisd.nl/
170
+
171
+ Please review each upstream project's license/terms. macblock does not vendor or redistribute these lists in this repository.
172
+
173
+ ## Security
174
+
175
+ See `SECURITY.md` for the threat model and privileged footprint.
176
+
177
+ ## Development
178
+
179
+ Tooling:
180
+
181
+ ```bash
182
+ brew install just direnv
183
+ ```
184
+
185
+ Then:
186
+
187
+ ```bash
188
+ direnv allow
189
+ just sync
190
+ just ci
191
+ ```
192
+
193
+ ## License
194
+
195
+ MIT
@@ -0,0 +1,163 @@
1
+ # macblock
2
+
3
+ [![CI](https://github.com/SpyicyDev/macblock/actions/workflows/ci.yml/badge.svg)](https://github.com/SpyicyDev/macblock/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+
6
+ Local DNS sinkhole for macOS using `dnsmasq` on `127.0.0.1:53`, with automatic system DNS configuration and split-DNS preservation.
7
+
8
+ ## Vibe-coding disclaimer
9
+
10
+ Most of this project was vibe-coded with careful code review and analysis of what the daemon touches. Every effort was made to ensure that the services here are using root as little as possible. If you find any holes I missed, please open an issue or a PR!
11
+
12
+ ## Features
13
+
14
+ - Blocks ads, trackers, and malware at the DNS level
15
+ - Automatically configures DNS for managed network services
16
+ - Preserves VPN/corporate split-DNS routing
17
+ - Pause/resume with automatic timers
18
+ - Whitelist/blacklist management
19
+ - Multiple blocklist sources (StevenBlack, HaGeZi, OISD) or a custom URL
20
+
21
+ ## Install
22
+
23
+ ### Via Homebrew (recommended)
24
+
25
+ ```bash
26
+ brew install SpyicyDev/formulae/macblock
27
+ ```
28
+
29
+ Or, if you prefer adding the tap explicitly:
30
+
31
+ ```bash
32
+ brew tap SpyicyDev/formulae
33
+ brew install macblock
34
+ ```
35
+
36
+ ### Quick start
37
+
38
+ `macblock` performs privileged operations (launchd + system DNS changes). You can run root-required commands with `sudo`, or omit it and let `macblock` auto-elevate.
39
+
40
+ ```bash
41
+ sudo macblock install
42
+ sudo macblock enable
43
+ macblock status
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```text
49
+ macblock <command> [flags]
50
+ ```
51
+
52
+ ### Global flags
53
+
54
+ - `-h`, `--help`: show help for a command
55
+ - `-V`, `--version`: show version
56
+
57
+ ### Commands
58
+
59
+ Status & diagnostics:
60
+
61
+ - `macblock status`: show current status
62
+ - `macblock doctor`: run diagnostics and health checks
63
+ - `macblock logs [--component daemon|dnsmasq] [--lines N] [--follow] [--stderr]`: view logs
64
+ - `macblock test <domain>`: test resolution against the local resolver
65
+
66
+ Control:
67
+
68
+ - `sudo macblock enable`: enable DNS blocking
69
+ - `sudo macblock disable`: disable DNS blocking
70
+ - `sudo macblock pause <duration>`: temporarily disable (e.g. `10m`, `2h`, `1d`)
71
+ - `sudo macblock resume`: resume blocking
72
+
73
+ Installation & updates:
74
+
75
+ - `sudo macblock install [--force] [--skip-update]`: install system integration
76
+ - `sudo macblock uninstall [--force]`: remove system integration
77
+ - `sudo macblock update [--source <name|url>] [--sha256 <hash>]`: download + compile blocklist and reload dnsmasq
78
+
79
+ Configuration:
80
+
81
+ - `macblock sources list`: list available blocklist sources
82
+ - `sudo macblock sources set <source>`: set blocklist source
83
+ - `macblock allow list`: list whitelisted domains
84
+ - `sudo macblock allow add|remove <domain>`: manage whitelist
85
+ - `macblock deny list`: list blacklisted domains
86
+ - `sudo macblock deny add|remove <domain>`: manage blacklist
87
+
88
+ Tip: `macblock <command> --help` shows per-command usage.
89
+
90
+ ## How it works
91
+
92
+ 1. `dnsmasq` listens on `127.0.0.1:53` and serves DNS.
93
+ 2. The macblock daemon watches for network changes and reconciles state.
94
+ 3. When enabled, macblock sets DNS to `127.0.0.1` for a set of managed macOS network services (it intentionally skips VPN-ish services/devices).
95
+ 4. macblock generates dnsmasq upstream routing from `scutil --dns` so domain-specific resolvers (VPN/corporate split-DNS) keep working.
96
+ 5. Blocked domains are answered as `NXDOMAIN` via dnsmasq rules.
97
+
98
+ Note: Encrypted DNS (DoH/DoT) can bypass macblock; `macblock doctor` warns if detected.
99
+
100
+ ## `macblock test` behavior
101
+
102
+ `macblock test <domain>` runs `dig` against `127.0.0.1:53` and uses the compiled block rules to interpret `NXDOMAIN`:
103
+
104
+ - If the domain matches a block rule, `NXDOMAIN` is reported as **BLOCKED**.
105
+ - If the domain does not match a block rule, `NXDOMAIN` is reported as **does not exist**.
106
+
107
+ If you don't have `dig`, install it with:
108
+
109
+ ```bash
110
+ brew install bind
111
+ ```
112
+
113
+ ## Uninstall
114
+
115
+ See `docs/UNINSTALL.md`.
116
+
117
+ Quick version:
118
+
119
+ ```bash
120
+ sudo macblock uninstall
121
+ brew uninstall macblock dnsmasq
122
+ ```
123
+
124
+ ## Troubleshooting
125
+
126
+ - Run `macblock doctor` first.
127
+ - View logs: `macblock logs --component daemon` or `macblock logs --component dnsmasq --stderr`.
128
+ - Verify DNS state: `scutil --dns` (macblock uses this to preserve split DNS).
129
+ - Port conflict on `:53`: `sudo lsof -i :53 -P -n`.
130
+
131
+ ## Attribution
132
+
133
+ macblock can download third-party blocklists from:
134
+
135
+ - StevenBlack hosts: https://github.com/StevenBlack/hosts
136
+ - HaGeZi DNS blocklists: https://github.com/hagezi/dns-blocklists
137
+ - OISD: https://oisd.nl/
138
+
139
+ Please review each upstream project's license/terms. macblock does not vendor or redistribute these lists in this repository.
140
+
141
+ ## Security
142
+
143
+ See `SECURITY.md` for the threat model and privileged footprint.
144
+
145
+ ## Development
146
+
147
+ Tooling:
148
+
149
+ ```bash
150
+ brew install just direnv
151
+ ```
152
+
153
+ Then:
154
+
155
+ ```bash
156
+ direnv allow
157
+ just sync
158
+ just ci
159
+ ```
160
+
161
+ ## License
162
+
163
+ MIT
@@ -0,0 +1,68 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "macblock"
7
+ version = "0.2.1"
8
+ description = "Local DNS sinkhole for macOS using dnsmasq"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "macbblock contributiers" }]
14
+ keywords = ["dns", "ad-blocker", "dnsmasq", "macos"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: End Users/Desktop",
19
+ "Operating System :: MacOS :: MacOS X",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Internet :: Name Service (DNS)",
26
+ "Topic :: Security",
27
+ ]
28
+ dependencies = []
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/SpyicyDev/macblock"
32
+ Repository = "https://github.com/SpyicyDev/macblock"
33
+ Issues = "https://github.com/SpyicyDev/macblock/issues"
34
+ Changelog = "https://github.com/SpyicyDev/macblock/blob/main/CHANGELOG.md"
35
+
36
+ [project.optional-dependencies]
37
+ dev = [
38
+ "ruff>=0.8.0",
39
+ "pyright>=1.1.390",
40
+ "pytest>=8.0.0",
41
+ "pytest-cov>=5.0.0",
42
+ ]
43
+
44
+ [dependency-groups]
45
+ dev = [
46
+ "ruff>=0.8.0",
47
+ "pyright>=1.1.390",
48
+ "pytest>=8.0.0",
49
+ "pytest-cov>=5.0.0",
50
+ ]
51
+
52
+ [tool.pytest.ini_options]
53
+ minversion = "8.0"
54
+ testpaths = ["tests"]
55
+ pythonpath = ["src"]
56
+ addopts = "-v --tb=short"
57
+
58
+ [project.scripts]
59
+ macblock = "macblock.cli:main"
60
+
61
+ [tool.setuptools]
62
+ package-dir = { "" = "src" }
63
+
64
+ [tool.setuptools.packages.find]
65
+ where = ["src"]
66
+
67
+ [tool.pyright]
68
+ extraPaths = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,8 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ try:
4
+ __version__ = version("macblock")
5
+ except PackageNotFoundError:
6
+ __version__ = "0.0.0"
7
+
8
+ __all__ = ["__version__"]
@@ -0,0 +1,4 @@
1
+ from macblock.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())