mdns-filoxy 1.0.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,70 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.11"
28
+
29
+ - name: Build release distributions
30
+ run: |
31
+ # NOTE: put your own distribution build steps here.
32
+ python -m pip install hatch
33
+ hatch build
34
+
35
+ - name: Upload distributions
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: release-dists
39
+ path: dist/
40
+
41
+ pypi-publish:
42
+ runs-on: ubuntu-latest
43
+ needs:
44
+ - release-build
45
+ permissions:
46
+ # IMPORTANT: this permission is mandatory for trusted publishing
47
+ id-token: write
48
+
49
+ # Dedicated environments with protections for publishing are strongly recommended.
50
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
51
+ environment:
52
+ name: pypi
53
+ # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
54
+ url: https://pypi.org/project/mdns-filoxy
55
+ #
56
+ # ALTERNATIVE: if your GitHub Release name is the PyPI project version string
57
+ # ALTERNATIVE: exactly, uncomment the following line instead:
58
+ # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
59
+
60
+ steps:
61
+ - name: Retrieve release distributions
62
+ uses: actions/download-artifact@v4
63
+ with:
64
+ name: release-dists
65
+ path: dist/
66
+
67
+ - name: Publish release distributions to PyPI
68
+ uses: pypa/gh-action-pypi-publish@release/v1
69
+ with:
70
+ packages-dir: dist/
@@ -0,0 +1,3 @@
1
+ /dist/
2
+ .idea/
3
+ /src/mdns_filoxy/_version.py
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present lingfish <jason@lucid.net.au>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: mdns-filoxy
3
+ Version: 1.0.1
4
+ Project-URL: Documentation, https://github.com/lingfish/mdns-filoxy/README.md
5
+ Project-URL: Issues, https://github.com/lingfish/mdns-filoxy/issues
6
+ Project-URL: Source, https://github.com/lingfish/mdns-filoxy
7
+ Author-email: Jason Lingohr <jason@lucid.net.au>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.txt
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Requires-Python: >=3.8
20
+ Requires-Dist: click
21
+ Requires-Dist: loguru
22
+ Requires-Dist: zeroconf
23
+ Description-Content-Type: text/markdown
24
+
25
+ # mdns-filoxy
26
+
27
+ [![PyPI - Version](https://img.shields.io/pypi/v/mdns-filoxy.svg)](https://pypi.org/project/mdns-filoxy)
28
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mdns-filoxy.svg)](https://pypi.org/project/mdns-filoxy)
29
+
30
+ -----
31
+
32
+ ![](logo-small.png)
33
+
34
+ This is mdns-filoxy, the mDNS filter proxy!
35
+
36
+ ## Table of contents
37
+
38
+ <!-- TOC -->
39
+ * [mdns-filoxy](#mdns-filoxy)
40
+ * [Table of contents](#table-of-contents)
41
+ * [Introduction](#introduction)
42
+ * [What is it for?](#what-is-it-for)
43
+ * [But isn't that what avahi-daemon et al are for?!](#but-isnt-that-what-avahi-daemon-et-al-are-for)
44
+ * [Draw me a picture](#draw-me-a-picture)
45
+ * [What's with the name?!](#whats-with-the-name)
46
+ * [Installation](#installation)
47
+ * [License](#license)
48
+ <!-- TOC -->
49
+
50
+ ## Introduction
51
+
52
+ Welcome to `mdns-filoxy`, the mDNS filter proxy.
53
+
54
+ ### What is it for?
55
+
56
+ `mdns-filoxy` allows you to send configured mDNS service queries out a specified interface, cache the response, and
57
+ then listen for further queries and answer them on a different interface.
58
+
59
+ This is particularly useful when you (rather smartly) put your IoT devices in a different network/VLAN to your "main"
60
+ network. I have my Sonos speakers setup this way, and without some form of proxy, I simply cannot talk to them
61
+ anymore, because of their odd use of mDNS and SSDP, and 14,000 other convoluted methods to reach their ecosystem.
62
+
63
+ ### But isn't that what avahi-daemon et al are for?!
64
+
65
+ `avahi-daemon` does have a reflector mode, and there are other packages like `mdns-repeater`. The issue is that they
66
+ both
67
+ listen for queries and then just re-send them out other interfaces. `avahi-daemon` even lets you filter reflections,
68
+ but they don't allow you to control the direction of the reflecting.
69
+
70
+ Furthermore, in the case where you have some other server on the same networks, with two or more interfaces bound to it,
71
+ `systemd` can have
72
+ a [rather major meltdown whilst it tries to think for you](https://github.com/home-assistant/supervisor/issues/5435) and
73
+ choose unique mDNS names. A good example of this is Home Assistant's HAOS.
74
+
75
+ ### Draw me a picture
76
+
77
+ Ok. Lets pretend you have a phone that sits in a VLAN, connected to a firewall interface called `eth0` (known as the
78
+ `dest-interface`). Lets further pretend your Sonos speaker is in another VLAN, connected to `iot0` (known as the
79
+ `--source-interface`).
80
+
81
+ When `mdns-filoxy` starts, it will bind to the specified interfaces, and on the source interface will query for the
82
+ chosen services (`--mdns-services`):
83
+
84
+ ```mermaid
85
+ flowchart LR
86
+ Firewall -->|iot0| mc[Multicast to VLAN
87
+ query for mdns-services] --> sonos[Speakers respond]-->|iot0 reply| Firewall
88
+ ```
89
+
90
+ `mdns-filoxy` caches that response, and then lies in wait, ready to respond to any queries that arrive on `eth0`.
91
+
92
+ Once `mdns-filoxy` is up and listening, here's the sequence of events:
93
+
94
+ ```mermaid
95
+ flowchart LR
96
+ phone[Phone
97
+ Sonos app
98
+ launched] --> mc[Multicast to VLAN
99
+ query for _sonos._tcp.local.] -->|eth0| Firewall -->|eth0 reply| phone
100
+ ```
101
+
102
+ Notice that the queries and responses aren't bi-directional, and this is intentional. The software is meant to give
103
+ minimal assistance to mDNS/IoT devices to get bootstrapped and then on with whatever other evil protocol(s) they use.
104
+
105
+ ### What's with the name?!
106
+
107
+ `filoxy` is my blend of "filter" and "proxy", as that's basically what this software does.
108
+
109
+ ## Installation
110
+
111
+ The recommended way to install `mdns-filoxy` is to use [pipx](https://pipx.pypa.io/stable/).
112
+
113
+ After getting `pipx` installed, simply run:
114
+
115
+ ```shell
116
+ username@host:~$ pipx install mdns-filoxy
117
+ ```
118
+
119
+ > [!WARNING]
120
+ > Please [don't use pip system-wide](https://docs.python.org/3.11/installing/index.html#installing-into-the-system-python-on-linux).
121
+
122
+ You can of course also install it using classic virtualenvs.
123
+
124
+ ## License
125
+
126
+ `mdns-filoxy` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,102 @@
1
+ # mdns-filoxy
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/mdns-filoxy.svg)](https://pypi.org/project/mdns-filoxy)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mdns-filoxy.svg)](https://pypi.org/project/mdns-filoxy)
5
+
6
+ -----
7
+
8
+ ![](logo-small.png)
9
+
10
+ This is mdns-filoxy, the mDNS filter proxy!
11
+
12
+ ## Table of contents
13
+
14
+ <!-- TOC -->
15
+ * [mdns-filoxy](#mdns-filoxy)
16
+ * [Table of contents](#table-of-contents)
17
+ * [Introduction](#introduction)
18
+ * [What is it for?](#what-is-it-for)
19
+ * [But isn't that what avahi-daemon et al are for?!](#but-isnt-that-what-avahi-daemon-et-al-are-for)
20
+ * [Draw me a picture](#draw-me-a-picture)
21
+ * [What's with the name?!](#whats-with-the-name)
22
+ * [Installation](#installation)
23
+ * [License](#license)
24
+ <!-- TOC -->
25
+
26
+ ## Introduction
27
+
28
+ Welcome to `mdns-filoxy`, the mDNS filter proxy.
29
+
30
+ ### What is it for?
31
+
32
+ `mdns-filoxy` allows you to send configured mDNS service queries out a specified interface, cache the response, and
33
+ then listen for further queries and answer them on a different interface.
34
+
35
+ This is particularly useful when you (rather smartly) put your IoT devices in a different network/VLAN to your "main"
36
+ network. I have my Sonos speakers setup this way, and without some form of proxy, I simply cannot talk to them
37
+ anymore, because of their odd use of mDNS and SSDP, and 14,000 other convoluted methods to reach their ecosystem.
38
+
39
+ ### But isn't that what avahi-daemon et al are for?!
40
+
41
+ `avahi-daemon` does have a reflector mode, and there are other packages like `mdns-repeater`. The issue is that they
42
+ both
43
+ listen for queries and then just re-send them out other interfaces. `avahi-daemon` even lets you filter reflections,
44
+ but they don't allow you to control the direction of the reflecting.
45
+
46
+ Furthermore, in the case where you have some other server on the same networks, with two or more interfaces bound to it,
47
+ `systemd` can have
48
+ a [rather major meltdown whilst it tries to think for you](https://github.com/home-assistant/supervisor/issues/5435) and
49
+ choose unique mDNS names. A good example of this is Home Assistant's HAOS.
50
+
51
+ ### Draw me a picture
52
+
53
+ Ok. Lets pretend you have a phone that sits in a VLAN, connected to a firewall interface called `eth0` (known as the
54
+ `dest-interface`). Lets further pretend your Sonos speaker is in another VLAN, connected to `iot0` (known as the
55
+ `--source-interface`).
56
+
57
+ When `mdns-filoxy` starts, it will bind to the specified interfaces, and on the source interface will query for the
58
+ chosen services (`--mdns-services`):
59
+
60
+ ```mermaid
61
+ flowchart LR
62
+ Firewall -->|iot0| mc[Multicast to VLAN
63
+ query for mdns-services] --> sonos[Speakers respond]-->|iot0 reply| Firewall
64
+ ```
65
+
66
+ `mdns-filoxy` caches that response, and then lies in wait, ready to respond to any queries that arrive on `eth0`.
67
+
68
+ Once `mdns-filoxy` is up and listening, here's the sequence of events:
69
+
70
+ ```mermaid
71
+ flowchart LR
72
+ phone[Phone
73
+ Sonos app
74
+ launched] --> mc[Multicast to VLAN
75
+ query for _sonos._tcp.local.] -->|eth0| Firewall -->|eth0 reply| phone
76
+ ```
77
+
78
+ Notice that the queries and responses aren't bi-directional, and this is intentional. The software is meant to give
79
+ minimal assistance to mDNS/IoT devices to get bootstrapped and then on with whatever other evil protocol(s) they use.
80
+
81
+ ### What's with the name?!
82
+
83
+ `filoxy` is my blend of "filter" and "proxy", as that's basically what this software does.
84
+
85
+ ## Installation
86
+
87
+ The recommended way to install `mdns-filoxy` is to use [pipx](https://pipx.pypa.io/stable/).
88
+
89
+ After getting `pipx` installed, simply run:
90
+
91
+ ```shell
92
+ username@host:~$ pipx install mdns-filoxy
93
+ ```
94
+
95
+ > [!WARNING]
96
+ > Please [don't use pip system-wide](https://docs.python.org/3.11/installing/index.html#installing-into-the-system-python-on-linux).
97
+
98
+ You can of course also install it using classic virtualenvs.
99
+
100
+ ## License
101
+
102
+ `mdns-filoxy` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
Binary file
Binary file
@@ -0,0 +1,76 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mdns-filoxy"
7
+ dynamic = ["version"]
8
+ description = ''
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ keywords = []
13
+ authors = [
14
+ { name = "Jason Lingohr", email = "jason@lucid.net.au" },
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Programming Language :: Python",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: Implementation :: CPython",
25
+ "Programming Language :: Python :: Implementation :: PyPy",
26
+ ]
27
+ dependencies = ["zeroconf", "click", "loguru"]
28
+
29
+ [project.urls]
30
+ Documentation = "https://github.com/lingfish/mdns-filoxy/README.md"
31
+ Issues = "https://github.com/lingfish/mdns-filoxy/issues"
32
+ Source = "https://github.com/lingfish/mdns-filoxy"
33
+
34
+ [project.scripts]
35
+ mdns-filoxy = "mdns_filoxy.main:entry_point"
36
+
37
+ [tool.hatch.version]
38
+ source = "vcs"
39
+
40
+ [tool.hatch.build.hooks.vcs]
41
+ version-file = "src/mdns_filoxy/_version.py"
42
+
43
+ [tool.hatch.envs.types]
44
+ extra-dependencies = [
45
+ "mypy>=1.0.0",
46
+ ]
47
+ [tool.hatch.envs.types.scripts]
48
+ check = "mypy --install-types --non-interactive {args:src/mdns_filoxy tests}"
49
+
50
+ [tool.coverage.run]
51
+ source_pkgs = ["mdns_filoxy", "tests"]
52
+ branch = true
53
+ parallel = true
54
+ omit = [
55
+ "src/mdns_filoxy/__about__.py",
56
+ ]
57
+
58
+ [tool.coverage.paths]
59
+ mdns_filoxy = ["src/mdns_filoxy", "*/mdns-filoxy/src/mdns_filoxy"]
60
+ tests = ["tests", "*/mdns-filoxy/tests"]
61
+
62
+ [tool.coverage.report]
63
+ exclude_lines = [
64
+ "no cov",
65
+ "if __name__ == .__main__.:",
66
+ "if TYPE_CHECKING:",
67
+ ]
68
+
69
+ [tool.hatch.build.targets.wheel]
70
+ packages = ["src/mdns_filoxy"]
71
+
72
+ [tool.ruff]
73
+ line-length = 120
74
+
75
+ [tool.ruff.format]
76
+ quote-style = "single"
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2025-present lingfish <jason@lucid.net.au>
2
+ #
3
+ # SPDX-License-Identifier: MIT
@@ -0,0 +1,34 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
12
+
13
+ TYPE_CHECKING = False
14
+ if TYPE_CHECKING:
15
+ from typing import Tuple
16
+ from typing import Union
17
+
18
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
20
+ else:
21
+ VERSION_TUPLE = object
22
+ COMMIT_ID = object
23
+
24
+ version: str
25
+ __version__: str
26
+ __version_tuple__: VERSION_TUPLE
27
+ version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
30
+
31
+ __version__ = version = '1.0.1'
32
+ __version_tuple__ = version_tuple = (1, 0, 1)
33
+
34
+ __commit_id__ = commit_id = None
@@ -0,0 +1,69 @@
1
+ import asyncio
2
+ import sys
3
+
4
+ import click
5
+ from zeroconf import ServiceBrowser, ServiceListener, Zeroconf
6
+ from loguru import logger
7
+
8
+ from mdns_filoxy.utils import find_address_by_name, coro
9
+ from mdns_filoxy._version import __version__
10
+
11
+ logger.remove()
12
+ logger.add(sys.stderr, backtrace=True, diagnose=True)
13
+
14
+
15
+ class MyListener(ServiceListener):
16
+ def __init__(self, dest_zc):
17
+ self.dest_zc = dest_zc
18
+ super().__init__()
19
+
20
+ def update_service(self, source_zc: Zeroconf, type_: str, name: str) -> None:
21
+ logger.info(f'Service {name} updated')
22
+
23
+ def remove_service(self, source_zc: Zeroconf, type_: str, name: str) -> None:
24
+ logger.info(f'Service {name} removed')
25
+
26
+ def add_service(self, source_zc: Zeroconf, type_: str, name: str) -> None:
27
+ info = source_zc.get_service_info(type_, name)
28
+ logger.info(f'Service {name} added')
29
+ self.dest_zc.register_service(info, cooperating_responders=True)
30
+ logger.info('Announcement sent')
31
+
32
+
33
+ @logger.catch
34
+ @click.command()
35
+ @click.version_option(version=__version__)
36
+ @click.option('--source-interface', '-s', required=True, help='The interface to proxy from')
37
+ @click.option('--dest-interface', '-d', required=True, help='The interface to proxy to, and answer requests on')
38
+ @click.option(
39
+ '--mdns-services', '-m', multiple=True, default=['_sonos._tcp.local.'], help='The mDNS services to listen for'
40
+ )
41
+ @coro
42
+ async def main(source_interface: str, dest_interface: str, mdns_services: list[str]) -> None:
43
+ """This is mdns-filoxy, the mDNS filter proxy!"""
44
+ zeroconf_source_address = find_address_by_name(source_interface)
45
+ zeroconf_dest_address = find_address_by_name(dest_interface)
46
+ logger.info(f'Listening on {source_interface} ({zeroconf_source_address}) for {mdns_services}')
47
+ zeroconf_source = Zeroconf(interfaces=zeroconf_source_address)
48
+ logger.info(f'Proxying {source_interface} to {dest_interface} ({zeroconf_dest_address})')
49
+ zeroconf_dest = Zeroconf(interfaces=zeroconf_dest_address)
50
+
51
+ for service in mdns_services:
52
+ listener = MyListener(dest_zc=zeroconf_dest)
53
+ browser = ServiceBrowser(zeroconf_source, service, listener)
54
+
55
+ try:
56
+ while True:
57
+ await asyncio.sleep(1)
58
+ finally:
59
+ logger.info('Shutdown')
60
+ zeroconf_dest.close()
61
+ zeroconf_source.close()
62
+
63
+
64
+ def entry_point() -> None:
65
+ asyncio.run(main())
66
+
67
+
68
+ if __name__ == '__main__':
69
+ entry_point()
@@ -0,0 +1,30 @@
1
+ import asyncio
2
+ from functools import wraps
3
+
4
+ import ifaddr
5
+
6
+
7
+ def get_all_addresses_ipv4(adapters: list[ifaddr.Adapter]) -> list[str]:
8
+ return list({addr.ip for iface in adapters for addr in iface.ips if addr.is_IPv4})
9
+
10
+
11
+ def get_all_addresses_ipv6(adapters: list[ifaddr.Adapter]) -> list[str]:
12
+ return list({addr.ip[0] for iface in adapters for addr in iface.ips if addr.is_IPv6})
13
+
14
+
15
+ def find_address_by_name(name: str) -> list[str]:
16
+ """Return a list of IP addresses based on interface name"""
17
+ ips = []
18
+ for adapter in ifaddr.get_adapters():
19
+ if adapter.name == name:
20
+ ips += get_all_addresses_ipv4([adapter]) + get_all_addresses_ipv6([adapter])
21
+ return ips
22
+
23
+
24
+ def coro(f):
25
+ """Make python click work with asyncio"""
26
+ @wraps(f)
27
+ def wrapper(*args, **kwargs):
28
+ return asyncio.run(f(*args, **kwargs))
29
+
30
+ return wrapper