Skip to content

Instantly share code, notes, and snippets.

@gongo
Created May 22, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gongo/ebcda016333fe1749ff0 to your computer and use it in GitHub Desktop.
Save gongo/ebcda016333fe1749ff0 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/armon/mdns"
"github.com/olekukonko/tablewriter"
"os"
"strconv"
)
func main() {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "IP address", "Port"})
entriesCh := make(chan *mdns.ServiceEntry, 4)
defer close(entriesCh)
go func() {
for entry := range entriesCh {
table.Append([]string{
entry.Name,
entry.Addr.String(),
strconv.Itoa(entry.Port),
})
}
}()
mdns.Lookup("_airplay._tcp", entriesCh)
table.Render()
}
// $ go run main.go
// +----------------+-------------+------+
// | NAME | IP ADDRESS | PORT |
// +----------------+-------------+------+
// | AppleTV.local. | 192.168.0.2 | 7000 |
// +----------------+-------------+------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment