Skip to content

Commit

Permalink
Add support for ip --router.
Browse files Browse the repository at this point in the history
  • Loading branch information
drn committed Jan 7, 2022
1 parent 5798527 commit c56e569
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/ip/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var services = []string{

// Options - Parsed input flags schema
var opts struct {
Local bool `short:"l" long:"local" description:"Return local IP of the specified interface (defaults to en0)"`
Local bool `short:"l" long:"local" description:"Return local IP of the specified interface (defaults to en0)"`
Router bool `short:"r" long:"router" description:"Return IP of LAN router"`
}

func main() {
Expand All @@ -40,6 +41,8 @@ func main() {
} else {
local("en0")
}
} else if opts.Router {
router()
} else {
external()
}
Expand Down
18 changes: 18 additions & 0 deletions cmd/ip/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"os"
"strings"

"github.com/drn/dots/pkg/log"
"github.com/drn/dots/pkg/run"
)

func router() {
info := run.Capture("netstat -nr | grep -m 1 default")
fields := strings.Fields(info)
if len(fields) < 2 || !isValid(fields[1]) {
os.Exit(1)
}
log.Info(fields[1])
}

0 comments on commit c56e569

Please sign in to comment.