• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This library implements Multicast DNS (mDNS) and DNS-Based Service Discovery (DNS-SD) for Zero Configuration Networking in Go.

DNS-SD

Build Status

This library implements Multicast DNS and DNS-Based Service Discovery to provide zero-configuration operations. It lets you announce and find services in a specific link-local domain.

Usage

Create a mDNS responder

The following code creates a service with name "My Website._http._tcp.local." for the host "My Computer" which has all IPs from network interface "eth0". The service is added to a responder.

import (
	"context"
	"github.com/brutella/dnssd"
)

cfg := dnssd.Config{
    Name:   "My Website",
    Type:   "_http._tcp",
    Domain: "local",
    Host:   "My Computer",
    Ifaces: []string{"eth0"},,
    Port:   12345,
}
sv, _ := dnssd.NewService(cfg)

In most cases you only need to specify the name, type and port of the service.

cfg := dnssd.Config{
    Name:   "My Website",
    Type:   "_http._tcp",
    Port:   12345,
}
sv, _ := dnssd.NewService(cfg)

Then you create a responder and add the service to it.

rp, _ := dnssd.NewResponder()
hdl, _ := rp.Add(sv)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

rp.Respond(ctx)

When calling Respond the responder probes for the service instance name and host name to be unqiue in the network. Once probing is finished, the service will be announced.

Update TXT records

Once a service is added to a responder, you can use the hdl to update properties.

hdl.UpdateText(map[string]string{"key1": "value1", "key2": "value2"}, rsp)

dnssd command

The command line tool in cmd/dnssd lets you browse, register and resolve services similar to dns-sd.

Install

You can install the tool with

go install github.com/brutella/dnssd/cmd/dnssd

Usage

Registering a service on your local machine

Lets register a printer service (_printer._tcp) running on your local computer at port 515 with the name "Private Printer".

dnssd register -Name="Private Printer" -Type="_printer._tcp" -Port=515

Registering a proxy service

If the service is running on a different machine on your local network, you have to specify the hostname and IP. Lets say the printer service is running on the printer with the hostname ABCD and IPv4 address 192.168.1.53, you can register a proxy which announce that service on your network.

dnssd register -Name="Private Printer" -Type="_printer._tcp" -Port=515 -IP=192.168.1.53 -Host=ABCD

Use option -Interface, if you want to announce the service only on a specific network interface. This might be necessary if your local machine is connected to multiple subnets and your announced service is only available on a specific subnet.

dnssd register -Name="Private Printer" -Type="_printer._tcp" -Port=515 -IP=192.168.1.53 -Host=ABCD -Interface=en0

Browsing for a service

If you want to browse for a service type, you can use the browse command.

dnssd browse -Type="_printer._tcp"

Resolving a service instance

If you know the name of a service instance, you can resolve its hostname with the resolve command.

dnssd resolve -Name="Private Printer" -Type="_printer._tcp"

Conformance

This library passes the multicast DNS tests of Apple's Bonjour Conformance Test.

TODO

  • Support hot plugging
  • Support negative responses (RFC6762 6.1)
  • Handle txt records case insensitive
  • Remove outdated services from cache regularly
  • Make sure that hostnames are FQDNs

Contact

Matthias Hochgatterer

Github: https://github.com/brutella

Twitter: https://twitter.com/brutella

License

dnssd is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

hc

hc is a lightweight framework to develop HomeKit accessories in Go.
Go
1,741
star
2

chatheads

An implementation of Facebook's ChatHeads on iOS.
Objective-C
883
star
3

hkcam

Open-Source HomeKit Surveillance Camera
Go
881
star
4

hap

The HomeKit Accessory Protocol (hap) implemented in Go
Go
289
star
5

can

Connect to a CAN bus in Go
Go
198
star
6

hklifx

LIFX HomeKit bridge
Go
106
star
7

hkknx-public

hkknx is a HomeKit KNX bridge for KNX.
89
star
8

swift-csv

Fast and memory-efficient CSV library in Swift.
Swift
80
star
9

hklight

Example project of a HomeKit light bulb using HomeControl
Go
39
star
10

canopen

Communicate with other CANopen nodes in Go
Go
26
star
11

TextViewLineNumbers

Implementation of NSTextView with line numbers
Swift
25
star
12

simplediff-swift

simplediff is a simple diff algorithm implementation in Swift.
Swift
16
star
13

nsuserdefaults-macros

Some handy NSUserDefaults macros/functions
Objective-C
15
star
14

NSTreePopUpButton

An NSPopUpButton subclass which supports binding to NSTreeController
Swift
15
star
15

uvr

Communicate with an UVR1611 over the CAN bus
Go
10
star
16

hkuvr1611

UVR1611 HomeKit bridge
Go
9
star
17

log-swift

Logging to console and file
Swift
9
star
18

Axt

A forgiving HTML SAX Parser for iOS
Objective-C
9
star
19

gouvr

Library to decode the data bus of UVR 1611 and similar devices
Go
7
star
20

hkuvr

HomeKit bridge for UVR1611
Go
5
star
21

hksymo

HomeKit bridge for Fronius Symo inverter
Go
3
star
22

Journal

Easy file logging in Swift
Swift
3
star
23

XCollectionData

Swift
2
star
24

comment-generator

Ruby classes to generate comment templates from source code
Ruby
2
star
25

git-diff

Compare git branches, tags and commits in your favourite diff tool.
Shell
1
star
26

C3Presentation

Slides about C++ programming built with deck.js and deckem
JavaScript
1
star
27

geizhals

Fetch prices from Geizhals
Go
1
star