python-zeroconf/python-zeroconf
GitHub: python-zeroconf/python-zeroconf
一个纯 Python 的多播 DNS 服务发现库,用于在网络中自动发现和注册服务。
Stars: 724 | Forks: 228
# un, I might not translate it. However, to output a line in Chinese, I could say "Python zeroconf" but that's not translated; it's just in English.
.. image:: https://github.com/python-zeroconf/python-zeroconf/workflows/CI/badge.svg
:target: https://github.com/python-zeroconf/python-zeroconf?query=workflow%3ACI+branch%3Amaster
.. image:: https://img.shields.io/pypi/v/zeroconf.svg
:target: https://pypi.python.org/pypi/zeroconf
.. image:: https://codecov.io/gh/python-zeroconf/python-zeroconf/branch/master/graph/badge.svg
:target: https://codecov.io/gh/python-zeroconf/python-zeroconf
.. image:: https://img.shields.io/endpoint?url=https://codspeed.io/badge.json
:target: https://codspeed.io/python-zeroconf/python-zeroconf
:alt: Codspeed.io status for python-zeroconf
.. image:: https://readthedocs.org/projects/python-zeroconf/badge/?version=latest
:target: https://python-zeroconf.readthedocs.io/en/latest/?badge=latest
:alt: 文档状态
`文档 `_。
这是 pyzeroconf 的一个分支,用于 Python 的多播 DNS 服务发现,
最初由 Paul Scott-Murphy (https://github.com/paulsm/pyzeroconf) 创建,
后经 William McBrine (https://github.com/wmcbrine/pyzeroconf) 修改。
William McBrine 原始的分支说明::
```
This fork is used in all of my TiVo-related projects: HME for Python
(and therefore HME/VLC), Network Remote, Remote Proxy, and pyTivo.
Before this, I was tracking the changes for zeroconf.py in three
separate repos. I figured I should have an authoritative source.
Although I make changes based on my experience with TiVos, I expect that
they're generally applicable. This version also includes patches found
on the now-defunct (?) Launchpad repo of pyzeroconf, and elsewhere
around the net -- not always well-documented, sorry.
```
兼容于:
* Bonjour
* Avahi
与其他一些 Zeroconf/Bonjour/Avahi Python 包相比,python-zeroconf:
* 不依赖于 Bonjour 或 Avahi
* 不使用 D-Bus
* 不强制要求使用特定的事件循环或 Twisted(内部使用 asyncio,但非必需)
* 可通过 pip 安装
* 在 PyPI 上发布
* 提供可选的 cython 扩展以提高性能(也支持纯 Python)
## Python 兼容性
* CPython 3.10+
* PyPy 3.10+
## 版本管理
本项目采用语义化版本控制。
## 状态
本项目处于积极维护中。
## 流量减少
在 0.32 版本之前,未实现 https://datatracker.ietf.org/doc/html/rfc6762#section-7 中描述的大部分流量减少技术,这可能导致网络流量过大。如果对此有顾虑,强烈建议使用 0.32 或更高版本。
## IPv6 支持
IPv6 支持相对较新且目前有限,具体如下:
* `InterfaceChoice.All` 在非 POSIX 系统上是 `InterfaceChoice.Default` 的别名。
* 使用了双栈 IPv6 套接字,这可能并非在所有地方都受支持(某些 BSD 变体没有)。
* 监听 localhost (`::1`) 不起作用。如果能帮助理解原因,将不胜感激。
# 如何获取 python-zeroconf?
* PyPI 页面 https://pypi.org/project/zeroconf/
* GitHub 项目 https://github.com/python-zeroconf/python-zeroconf
安装 python-zeroconf 最简单的方法是使用 pip::
```
pip install zeroconf
```
# 如何使用?
以下是浏览服务的示例:
.. code-block:: python
```
from zeroconf import ServiceBrowser, ServiceListener, Zeroconf
class MyListener(ServiceListener):
def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
print(f"Service {name} updated")
def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
print(f"Service {name} removed")
def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
info = zc.get_service_info(type_, name)
print(f"Service {name} added, service info: {info}")
zeroconf = Zeroconf()
listener = MyListener()
browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener)
try:
input("Press enter to exit...\n\n")
finally:
zeroconf.close()
```
.. note::
```
Discovery and service registration use *all* available network interfaces by default.
If you want to customize that you need to specify ``interfaces`` argument when
constructing ``Zeroconf`` object (see the code for details).
```
如果你不知道需要浏览的服务名称,请尝试:
.. code-block:: python
```
from zeroconf import ZeroconfServiceTypes
print('\n'.join(ZeroconfServiceTypes.find()))
```
更多示例请参见 examples 目录。
# 更新日志
`更新日志 `_
# 许可证
LGPL,详见 COPYING 文件。
标签:Avahi兼容, Bonjour兼容, DNS服务发现, pip包, Python, Zeroconf, 多播DNS, 开源, 异步IO, 无后门, 服务发现, 本地网络, 纯Python实现, 网络库, 网络编程, 自动发现, 计算机取证, 逆向工具