Giter VIP home page Giter VIP logo

zeroconf's Introduction

Zeroconf

A simple Python 2.7 interface to Zeroconf service discovery and registration.

Installation

Requirements

The zeroconf module assumes that the avahi command-line tools avahi-browse and avahi-publish are available. On Ubuntu for example, they may me installed with:

$ sudo apt-get install avahi-tools

The module also depend on Andrew Moffat's subprocess wrapper. Install it with

$ sudo pip install sh

Install

Download the source distribution and type:

$ sudo python setup.py install

Usage

Zeroconf Services Discovery

Searching for all available Zeroconf services is done by

>>> import zeroconf
>>> services = zeroconf.search()

The search can be made more specific, for example:

>>> services = zeroconf.search(name=None, type="_workstation._tcp", domain="local")

The arguments, all optional, to the search functions are:

  • name: service name, defaults to None (interpreted as all),
  • type: service type, defaults to None (interpreted as all),
  • domain: domain name, defaults to "local".

Search results are dictionaries:

>>> print services
{('tide [f0:7b:cb:42:ff:e0]', '_workstation._tcp', 'local'): 
   {'txt': '', 'hostname': 'tide.local', 'port': '9', 'address': '192.168.0.13'}, 
 ('wreck [00:26:18:4c:3f:ee]', '_workstation._tcp', 'local'): 
   {'txt': '', 'hostname': 'wreck.local', 'port': '9', 'address': '192.168.0.10'}, 
 ('biohazard [00:18:8b:ac:c8:45]', '_workstation._tcp', 'local'): 
   {'txt': '', 'hostname': 'biohazard.local', 'port': '9', 'address': '192.168.0.12'}}

The keys are (name, type, domain) tuples and the values are dictionaries with txt, hostname, port and address keys.

Zeroconf Services Registration

Register a new zeroconf service in the local domain with:

>>> zeroconf.register(name="ghost [08:00:27:bf:49:e1]", type="_workstation._tcp", port="9")

and when you're done, unregister it with:

>>> zeroconf.unregister(name="ghost [08:00:27:bf:49:e1]", type="_workstation._tcp", port="9")

All arguments to unregister are optional, so we could have done:

>>> zeroconf.unregister(name="ghost [08:00:27:bf:49:e1]")

or even, to unregister all services published during the Python session:

>>> zeroconf.unregister()

Contributors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.