mdns-filoxy 1.0.5__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.
- mdns_filoxy-1.0.5/.github/workflows/python-publish.yml +70 -0
- mdns_filoxy-1.0.5/.gitignore +3 -0
- mdns_filoxy-1.0.5/LICENSE.txt +9 -0
- mdns_filoxy-1.0.5/PKG-INFO +128 -0
- mdns_filoxy-1.0.5/README.md +103 -0
- mdns_filoxy-1.0.5/logo-small.png +0 -0
- mdns_filoxy-1.0.5/logo.png +0 -0
- mdns_filoxy-1.0.5/pyproject.toml +76 -0
- mdns_filoxy-1.0.5/src/mdns_filoxy/__init__.py +3 -0
- mdns_filoxy-1.0.5/src/mdns_filoxy/_version.py +34 -0
- mdns_filoxy-1.0.5/src/mdns_filoxy/main.py +80 -0
- mdns_filoxy-1.0.5/src/mdns_filoxy/utils.py +30 -0
|
@@ -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,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,128 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mdns-filoxy
|
|
3
|
+
Version: 1.0.5
|
|
4
|
+
Summary: This is mdns-filoxy, the mDNS filter proxy!
|
|
5
|
+
Project-URL: Documentation, https://github.com/lingfish/mdns-filoxy
|
|
6
|
+
Project-URL: Issues, https://github.com/lingfish/mdns-filoxy/issues
|
|
7
|
+
Project-URL: Source, https://github.com/lingfish/mdns-filoxy
|
|
8
|
+
Author-email: Jason Lingohr <jason@lucid.net.au>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Requires-Dist: click
|
|
22
|
+
Requires-Dist: loguru
|
|
23
|
+
Requires-Dist: zeroconf
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# mdns-filoxy
|
|
27
|
+
|
|
28
|
+
[](https://pypi.org/project/mdns-filoxy)
|
|
29
|
+
[](https://pypi.org/project/mdns-filoxy)
|
|
30
|
+
|
|
31
|
+
-----
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
This is mdns-filoxy, the mDNS filter proxy!
|
|
36
|
+
|
|
37
|
+
## Table of contents
|
|
38
|
+
|
|
39
|
+
<!-- TOC -->
|
|
40
|
+
* [mdns-filoxy](#mdns-filoxy)
|
|
41
|
+
* [Table of contents](#table-of-contents)
|
|
42
|
+
* [Introduction](#introduction)
|
|
43
|
+
* [What is it for?](#what-is-it-for)
|
|
44
|
+
* [But isn't that what avahi-daemon et al are for?!](#but-isnt-that-what-avahi-daemon-et-al-are-for)
|
|
45
|
+
* [Draw me a picture](#draw-me-a-picture)
|
|
46
|
+
* [What's with the name?!](#whats-with-the-name)
|
|
47
|
+
* [Installation](#installation)
|
|
48
|
+
* [License](#license)
|
|
49
|
+
<!-- TOC -->
|
|
50
|
+
|
|
51
|
+
## Introduction
|
|
52
|
+
|
|
53
|
+
Welcome to `mdns-filoxy`, the mDNS filter proxy.
|
|
54
|
+
|
|
55
|
+
### What is it for?
|
|
56
|
+
|
|
57
|
+
`mdns-filoxy` allows you to send configured mDNS service queries out a specified interface, cache the response, and
|
|
58
|
+
then listen for further queries and answer them on a different interface.
|
|
59
|
+
|
|
60
|
+
This is particularly useful when you (rather smartly) put your IoT devices in a different network/VLAN to your "main"
|
|
61
|
+
network. I have my Sonos speakers setup this way, and without some form of proxy, I simply cannot talk to them
|
|
62
|
+
anymore, because of their odd use of mDNS and SSDP, and 14,000 other convoluted methods to reach their ecosystem.
|
|
63
|
+
|
|
64
|
+
### But isn't that what avahi-daemon et al are for?!
|
|
65
|
+
|
|
66
|
+
`avahi-daemon` does have a reflector mode, and there are other packages like `mdns-repeater`. The issue is that they
|
|
67
|
+
both
|
|
68
|
+
listen for queries and then just re-send them out other interfaces. `avahi-daemon` even lets you filter reflections,
|
|
69
|
+
but they don't allow you to control the direction of the reflecting.
|
|
70
|
+
|
|
71
|
+
Furthermore, in the case where you have some other server on the same networks, with two or more interfaces bound to it,
|
|
72
|
+
`systemd` can have
|
|
73
|
+
a [rather major meltdown whilst it tries to think for you](https://github.com/home-assistant/supervisor/issues/5435) and
|
|
74
|
+
choose unique mDNS names. A good example of this is Home Assistant's HAOS.
|
|
75
|
+
`systemd` [behaves badly](https://github.com/systemd/systemd/issues/35780) with mdns repeaters too.
|
|
76
|
+
|
|
77
|
+
### Draw me a picture
|
|
78
|
+
|
|
79
|
+
Ok. Lets pretend you have a phone that sits in a VLAN, connected to a firewall interface called `eth0` (known as the
|
|
80
|
+
`dest-interface`). Lets further pretend your Sonos speaker is in another VLAN, connected to `iot0` (known as the
|
|
81
|
+
`--source-interface`).
|
|
82
|
+
|
|
83
|
+
When `mdns-filoxy` starts, it will bind to the specified interfaces, and on the source interface will query for the
|
|
84
|
+
chosen services (`--mdns-services`):
|
|
85
|
+
|
|
86
|
+
```mermaid
|
|
87
|
+
flowchart LR
|
|
88
|
+
Firewall -->|iot0| mc[Multicast to VLAN
|
|
89
|
+
query for mdns-services] --> sonos[Speakers respond]-->|iot0 reply| Firewall
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`mdns-filoxy` caches that response, and then lies in wait, ready to respond to any queries that arrive on `eth0`.
|
|
93
|
+
|
|
94
|
+
Once `mdns-filoxy` is up and listening, here's the sequence of events:
|
|
95
|
+
|
|
96
|
+
```mermaid
|
|
97
|
+
flowchart LR
|
|
98
|
+
phone[Phone
|
|
99
|
+
Sonos app
|
|
100
|
+
launched] --> mc[Multicast to VLAN
|
|
101
|
+
query for _sonos._tcp.local.] -->|eth0| Firewall -->|eth0 reply| phone
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Notice that the queries and responses aren't bi-directional, and this is intentional. The software is meant to give
|
|
105
|
+
minimal assistance to mDNS/IoT devices to get bootstrapped and then on with whatever other evil protocol(s) they use.
|
|
106
|
+
|
|
107
|
+
### What's with the name?!
|
|
108
|
+
|
|
109
|
+
`filoxy` is my blend of "filter" and "proxy", as that's basically what this software does.
|
|
110
|
+
|
|
111
|
+
## Installation
|
|
112
|
+
|
|
113
|
+
The recommended way to install `mdns-filoxy` is to use [pipx](https://pipx.pypa.io/stable/).
|
|
114
|
+
|
|
115
|
+
After getting `pipx` installed, simply run:
|
|
116
|
+
|
|
117
|
+
```shell
|
|
118
|
+
username@host:~$ pipx install mdns-filoxy
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
> [!WARNING]
|
|
122
|
+
> Please [don't use pip system-wide](https://docs.python.org/3.11/installing/index.html#installing-into-the-system-python-on-linux).
|
|
123
|
+
|
|
124
|
+
You can of course also install it using classic virtualenvs.
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
`mdns-filoxy` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# mdns-filoxy
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/mdns-filoxy)
|
|
4
|
+
[](https://pypi.org/project/mdns-filoxy)
|
|
5
|
+
|
|
6
|
+
-----
|
|
7
|
+
|
|
8
|
+

|
|
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
|
+
`systemd` [behaves badly](https://github.com/systemd/systemd/issues/35780) with mdns repeaters too.
|
|
51
|
+
|
|
52
|
+
### Draw me a picture
|
|
53
|
+
|
|
54
|
+
Ok. Lets pretend you have a phone that sits in a VLAN, connected to a firewall interface called `eth0` (known as the
|
|
55
|
+
`dest-interface`). Lets further pretend your Sonos speaker is in another VLAN, connected to `iot0` (known as the
|
|
56
|
+
`--source-interface`).
|
|
57
|
+
|
|
58
|
+
When `mdns-filoxy` starts, it will bind to the specified interfaces, and on the source interface will query for the
|
|
59
|
+
chosen services (`--mdns-services`):
|
|
60
|
+
|
|
61
|
+
```mermaid
|
|
62
|
+
flowchart LR
|
|
63
|
+
Firewall -->|iot0| mc[Multicast to VLAN
|
|
64
|
+
query for mdns-services] --> sonos[Speakers respond]-->|iot0 reply| Firewall
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`mdns-filoxy` caches that response, and then lies in wait, ready to respond to any queries that arrive on `eth0`.
|
|
68
|
+
|
|
69
|
+
Once `mdns-filoxy` is up and listening, here's the sequence of events:
|
|
70
|
+
|
|
71
|
+
```mermaid
|
|
72
|
+
flowchart LR
|
|
73
|
+
phone[Phone
|
|
74
|
+
Sonos app
|
|
75
|
+
launched] --> mc[Multicast to VLAN
|
|
76
|
+
query for _sonos._tcp.local.] -->|eth0| Firewall -->|eth0 reply| phone
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Notice that the queries and responses aren't bi-directional, and this is intentional. The software is meant to give
|
|
80
|
+
minimal assistance to mDNS/IoT devices to get bootstrapped and then on with whatever other evil protocol(s) they use.
|
|
81
|
+
|
|
82
|
+
### What's with the name?!
|
|
83
|
+
|
|
84
|
+
`filoxy` is my blend of "filter" and "proxy", as that's basically what this software does.
|
|
85
|
+
|
|
86
|
+
## Installation
|
|
87
|
+
|
|
88
|
+
The recommended way to install `mdns-filoxy` is to use [pipx](https://pipx.pypa.io/stable/).
|
|
89
|
+
|
|
90
|
+
After getting `pipx` installed, simply run:
|
|
91
|
+
|
|
92
|
+
```shell
|
|
93
|
+
username@host:~$ pipx install mdns-filoxy
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
> [!WARNING]
|
|
97
|
+
> Please [don't use pip system-wide](https://docs.python.org/3.11/installing/index.html#installing-into-the-system-python-on-linux).
|
|
98
|
+
|
|
99
|
+
You can of course also install it using classic virtualenvs.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
`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 = "This is mdns-filoxy, the mDNS filter proxy!"
|
|
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 :: 5 - Production/Stable",
|
|
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"
|
|
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,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.5'
|
|
32
|
+
__version_tuple__ = version_tuple = (1, 0, 5)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
@click.option(
|
|
42
|
+
'--spotify-connect/--no-spotify-connect',
|
|
43
|
+
'--spotify/--no-spotify',
|
|
44
|
+
default=True,
|
|
45
|
+
help='Add the suitable Spotify connect mDNS entry',
|
|
46
|
+
)
|
|
47
|
+
@coro
|
|
48
|
+
async def main(source_interface: str, dest_interface: str, mdns_services: tuple[str], spotify_connect: bool) -> None:
|
|
49
|
+
"""This is mdns-filoxy, the mDNS filter proxy!"""
|
|
50
|
+
|
|
51
|
+
if spotify_connect:
|
|
52
|
+
mdns_services+=('_spotify-connect._tcp.local.',)
|
|
53
|
+
|
|
54
|
+
zeroconf_source_address = find_address_by_name(source_interface)
|
|
55
|
+
zeroconf_dest_address = find_address_by_name(dest_interface)
|
|
56
|
+
|
|
57
|
+
logger.info(f'Listening on {source_interface} ({zeroconf_source_address}) for {mdns_services}')
|
|
58
|
+
zeroconf_source = Zeroconf(interfaces=zeroconf_source_address)
|
|
59
|
+
logger.info(f'Proxying {source_interface} to {dest_interface} ({zeroconf_dest_address})')
|
|
60
|
+
zeroconf_dest = Zeroconf(interfaces=zeroconf_dest_address)
|
|
61
|
+
|
|
62
|
+
for service in mdns_services:
|
|
63
|
+
listener = MyListener(dest_zc=zeroconf_dest)
|
|
64
|
+
browser = ServiceBrowser(zeroconf_source, service, listener)
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
while True:
|
|
68
|
+
await asyncio.sleep(1)
|
|
69
|
+
finally:
|
|
70
|
+
logger.info('Shutdown')
|
|
71
|
+
zeroconf_dest.close()
|
|
72
|
+
zeroconf_source.close()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def entry_point() -> None:
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if __name__ == '__main__':
|
|
80
|
+
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
|