forked from aliask/oui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 1006 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/aliask/oui/ouidb"
"github.com/spf13/cobra"
)
func main() {
var rootCmd = &cobra.Command{
Use: "oui",
Short: "OIU lookup tool",
}
var lookupCmd = &cobra.Command{
Use: "lookup [MAC Address]",
Short: "Perform lookup",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
ouidb.Lookup(args[0])
} else {
fmt.Println("Please provide a MAC address or use the 'update' command.")
}
},
}
rootCmd.AddCommand(lookupCmd)
updateCmd := &cobra.Command{
Use: "update",
Short: "Update the OUI database from IEEE",
Run: func(cmd *cobra.Command, args []string) {
ouidb.UpdateDatabase()
},
}
rootCmd.AddCommand(updateCmd)
// default to performing lookup if no valid command is given
_, _, err := rootCmd.Find(os.Args[1:])
if err != nil {
args := append([]string{"lookup"}, os.Args[1:]...)
rootCmd.SetArgs(args)
}
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}