mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
new: net.show now accepts a comma separated list of ip, macs or aliases to filter for
This commit is contained in:
parent
09caa4dd37
commit
a2b3ee79fb
4 changed files with 52 additions and 32 deletions
|
@ -81,6 +81,19 @@ func (lan *LAN) Get(mac string) (*Endpoint, bool) {
|
|||
return nil, false
|
||||
}
|
||||
|
||||
func (lan *LAN) GetByIp(ip string) *Endpoint {
|
||||
lan.Lock()
|
||||
defer lan.Unlock()
|
||||
|
||||
for _, e := range lan.hosts {
|
||||
if e.IpAddress == ip {
|
||||
return e
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lan *LAN) List() (list []*Endpoint) {
|
||||
lan.Lock()
|
||||
defer lan.Unlock()
|
||||
|
@ -169,19 +182,6 @@ func (lan *LAN) EachHost(cb func(mac string, e *Endpoint)) {
|
|||
}
|
||||
}
|
||||
|
||||
func (lan *LAN) GetByIp(ip string) *Endpoint {
|
||||
lan.Lock()
|
||||
defer lan.Unlock()
|
||||
|
||||
for _, e := range lan.hosts {
|
||||
if e.IpAddress == ip {
|
||||
return e
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lan *LAN) AddIfNew(ip, mac string) *Endpoint {
|
||||
lan.Lock()
|
||||
defer lan.Unlock()
|
||||
|
|
|
@ -118,6 +118,32 @@ func ParseTargets(targets string, aliasMap *Aliases) (ips []net.IP, macs []net.H
|
|||
return
|
||||
}
|
||||
|
||||
func ParseEndpoints(targets string, lan *LAN) ([]*Endpoint, error) {
|
||||
ips, macs, err := ParseTargets(targets, lan.Aliases())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tmp := make(map[string]*Endpoint)
|
||||
for _, ip := range ips {
|
||||
if e := lan.GetByIp(ip.String()); e != nil {
|
||||
tmp[e.HW.String()] = e
|
||||
}
|
||||
}
|
||||
|
||||
for _, mac := range macs {
|
||||
if e, found := lan.Get(mac.String()); found {
|
||||
tmp[e.HW.String()] = e
|
||||
}
|
||||
}
|
||||
|
||||
ret := make([]*Endpoint, 0)
|
||||
for _, e := range tmp {
|
||||
ret = append(ret, e)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func buildEndpointFromInterface(iface net.Interface) (*Endpoint, error) {
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue