-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (69 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Discovery tool for sane-airscan compatible devices
//
// Copyright (C) 2020 and up by Alexander Pevzner ([email protected])
// See LICENSE for license terms and conditions
//
// The main function
package main
import (
"fmt"
"os"
"time"
)
// Usage/usage error templates
const usage = `Usage:
%s [options]
Options are:
-d enable debug mode
-t enable protocol trace
-h print help page
`
const usageError = `Invalid argument -%s
Try %s -h for more information
`
// The main function
func main() {
// Parse options
for _, arg := range os.Args[1:] {
switch arg {
case "-d":
Debug = true
case "-t":
Debug = true
Trace = true
case "-h":
fmt.Printf(usage, os.Args[0])
os.Exit(0)
default:
fmt.Printf(usageError, arg, os.Args[0])
os.Exit(1)
}
}
// Perform a discovery
c := make(chan Endpoint)
t := time.NewTimer(2500 * time.Millisecond)
endpoints := make(map[Endpoint]struct{})
go DNSSdDiscover(c)
go WSSDDiscover(c)
loop:
for {
select {
case endpoint := <-c:
endpoints[endpoint] = struct{}{}
case <-t.C:
break loop
}
}
// Output results
if Debug {
fmt.Printf("\n")
}
fmt.Printf("[devices]\n")
for endpoint := range endpoints {
line := fmt.Sprintf("%q = %s", endpoint.Name, endpoint.URL)
if endpoint.Proto != "" {
line += ", " + endpoint.Proto
}
fmt.Printf(" %s\n", line)
}
}