add -i flag to filter by single interface
This commit is contained in:
3
arp.go
3
arp.go
@@ -37,6 +37,9 @@ func (t *Tendrils) readARPTable() {
|
|||||||
entries := t.parseARPTable()
|
entries := t.parseARPTable()
|
||||||
|
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
|
if t.iface != "" && entry.iface != t.iface {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if isBroadcastOrZero(entry.mac) {
|
if isBroadcastOrZero(entry.mac) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
|
||||||
"github.com/gopatchy/tendrils"
|
"github.com/gopatchy/tendrils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
t := tendrils.New()
|
iface := flag.String("i", "", "interface to use (default: all interfaces)")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
t := tendrils.New(*iface)
|
||||||
t.Run()
|
t.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import (
|
|||||||
type Tendrils struct {
|
type Tendrils struct {
|
||||||
activeInterfaces map[string]context.CancelFunc
|
activeInterfaces map[string]context.CancelFunc
|
||||||
nodes *Nodes
|
nodes *Nodes
|
||||||
|
iface string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Tendrils {
|
func New(iface string) *Tendrils {
|
||||||
return &Tendrils{
|
return &Tendrils{
|
||||||
activeInterfaces: map[string]context.CancelFunc{},
|
activeInterfaces: map[string]context.CancelFunc{},
|
||||||
nodes: NewNodes(),
|
nodes: NewNodes(),
|
||||||
|
iface: iface,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +90,9 @@ func (t *Tendrils) listInterfaces() []net.Interface {
|
|||||||
|
|
||||||
var validInterfaces []net.Interface
|
var validInterfaces []net.Interface
|
||||||
for _, iface := range interfaces {
|
for _, iface := range interfaces {
|
||||||
|
if t.iface != "" && iface.Name != t.iface {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if iface.Flags&net.FlagUp == 0 {
|
if iface.Flags&net.FlagUp == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user