syncthing/cmd/stfinddevice/main.go

48 lines
1.1 KiB
Go
Raw Normal View History

2014-12-25 23:12:12 +00:00
// Copyright (C) 2014 The Syncthing Authors.
//
2015-03-07 20:36:35 +00:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
2014-12-25 23:12:12 +00:00
package main
import (
"flag"
"log"
"os"
"github.com/syncthing/protocol"
2015-08-06 09:29:25 +00:00
"github.com/syncthing/syncthing/lib/discover"
2014-12-25 23:12:12 +00:00
)
func main() {
log.SetFlags(0)
log.SetOutput(os.Stdout)
var server string
flag.StringVar(&server, "server", "udp4://announce.syncthing.net:22027", "Announce server")
2014-12-25 23:12:12 +00:00
flag.Parse()
if len(flag.Args()) != 1 || server == "" {
log.Printf("Usage: %s [-server=\"udp4://announce.syncthing.net:22027\"] <device>", os.Args[0])
2014-12-25 23:12:12 +00:00
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, nil)
2015-09-12 19:59:15 +00:00
discoverer.StartGlobal([]string{server}, nil)
addresses, relays := discoverer.Lookup(id)
for _, addr := range addresses {
log.Println("address:", addr)
}
for _, addr := range relays {
log.Println("relay:", addr)
2014-12-25 23:12:12 +00:00
}
}