python-zeroconf, 一种纯 python 组播服务发现的实现

分享于 

4分钟阅读

GitHub

 
A pure python implementation of multicast DNS service discovery
  • 源代码名称:python-zeroconf
  • 源代码网址:https://github.com/jstasiak/python-zeroconf
  • python-zeroconf源代码文档
  • python-zeroconf源代码下载
  • Git URL:
    https://github.com/jstasiak/python-zeroconf.git
    Git Clone代码到本地:
    git clone https://github.com/jstasiak/python-zeroconf
    Subversion代码到本地:
    $ svn co --depth empty https://github.com/jstasiak/python-zeroconf
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    

    python-zeroconf

    这是pyzeroconf的分支,它是Python的多播DNS服务发现,最初是由Paul Scott-Murphy(),由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

    与其他Zerozero/Bonjour/Avahi Python软件包相比,python-zeroconf:

    Bonjour或Avahi无关 不使用D-Bus 不强制使用特定的事件循环或Twisted pip可安装 PyPI分发

    python兼容性

    CPython 3.4 + PyPy3 5.8 +

    版本管理

    此项目的版本遵循以下模式:MAJOR.MINOR.PATCH。

    目前主要版本是0 向后不兼容的更改会增加MINOR版本 修补程序版本在向后兼容更改时递增

    状态

    如何获取python zeroconf?

    PyPI页面https://pypi.python.org/pypi/zeroconf GitHub项目https://github.com/jstasiak/python-zeroconf

    安装python zeroconf的最简单方法是使用pip:

    pip install zeroconf

    如何使用它?

    以下是浏览服务的示例:

    from zeroconf import ServiceBrowser, ZeroconfclassMyListener:
     defremove_service(self, zeroconf, type, name):
     print("Service %s removed"% (name,))
     defadd_service(self, zeroconf, type, name):
     info = zeroconf.get_service_info(type, name)
     print("Service %s added, service info: %s"% (name, info))
    zeroconf = Zeroconf()
    listener = MyListener()
    browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener)try:
     input("Press enter to exit...nn")finally:
     zeroconf.close()

    注意

    发现和服务注册默认使用所有可用的网络接口,如果要自定义在构造interfaces对象时需要指定参数Zeroconf对象(有关详细信息,请参见代码)。

    如果不知道要浏览的服务的名称,请尝试:

    from zeroconf import ZeroconfServiceTypesprint('n'.join(ZeroconfServiceTypes.find()))

    有关更多信息,请参见示例目录。


    相关文章