From 12eabb220de60af6126d1dd16259742510ed16c2 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Thu, 25 Dec 2014 23:12:12 +0000 Subject: [PATCH] Add device finder utility --- cmd/stfinddevice/main.go | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cmd/stfinddevice/main.go diff --git a/cmd/stfinddevice/main.go b/cmd/stfinddevice/main.go new file mode 100644 index 000000000..b772327fb --- /dev/null +++ b/cmd/stfinddevice/main.go @@ -0,0 +1,52 @@ +// Copyright (C) 2014 The Syncthing Authors. +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along +// with this program. If not, see . + +package main + +import ( + "flag" + "log" + "os" + + "github.com/syncthing/syncthing/internal/discover" + "github.com/syncthing/syncthing/internal/protocol" +) + +func main() { + log.SetFlags(0) + log.SetOutput(os.Stdout) + + var server string + + flag.StringVar(&server, "server", "udp4://announce.syncthing.net:22026", "Announce server") + flag.Parse() + + if len(flag.Args()) != 1 || server == "" { + log.Printf("Usage: %s [-server=\"udp4://announce.syncthing.net:22026\"] ", os.Args[0]) + os.Exit(64) + } + + id, err := protocol.DeviceIDFromString(flag.Args()[0]) + if err != nil { + log.Println(err) + os.Exit(1) + } + + discoverer := discover.NewDiscoverer(protocol.LocalDeviceID, nil) + discoverer.StartGlobal([]string{server}, 1) + for _, addr := range discoverer.Lookup(id) { + log.Println(addr) + } +}