mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
new: aliases are now centralized and can be used for any type of device (closes #504)
This commit is contained in:
parent
96853e663b
commit
7e7f2ef645
11 changed files with 115 additions and 51 deletions
|
@ -2,23 +2,18 @@ package network
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/evilsocket/islazy/data"
|
||||
"github.com/evilsocket/islazy/fs"
|
||||
)
|
||||
|
||||
const LANDefaultttl = 10
|
||||
const LANAliasesFile = "~/bettercap.aliases"
|
||||
|
||||
type EndpointNewCallback func(e *Endpoint)
|
||||
type EndpointLostCallback func(e *Endpoint)
|
||||
|
||||
var aliasesFileName, _ = fs.Expand(LANAliasesFile)
|
||||
|
||||
type LAN struct {
|
||||
sync.Mutex
|
||||
hosts map[string]*Endpoint
|
||||
|
@ -34,12 +29,7 @@ type lanJSON struct {
|
|||
Hosts []*Endpoint `json:"hosts"`
|
||||
}
|
||||
|
||||
func NewLAN(iface, gateway *Endpoint, newcb EndpointNewCallback, lostcb EndpointLostCallback) *LAN {
|
||||
aliases, err := data.NewUnsortedKV(aliasesFileName, data.FlushOnEdit)
|
||||
if err != nil {
|
||||
fmt.Printf("error loading %s: %s", aliasesFileName, err)
|
||||
}
|
||||
|
||||
func NewLAN(iface, gateway *Endpoint, aliases *data.UnsortedKV, newcb EndpointNewCallback, lostcb EndpointLostCallback) *LAN {
|
||||
return &LAN{
|
||||
iface: iface,
|
||||
gateway: gateway,
|
||||
|
@ -63,19 +53,6 @@ func (l *LAN) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(doc)
|
||||
}
|
||||
|
||||
func (lan *LAN) SetAliasFor(mac, alias string) bool {
|
||||
lan.Lock()
|
||||
defer lan.Unlock()
|
||||
|
||||
mac = NormalizeMac(mac)
|
||||
lan.aliases.Set(mac, alias)
|
||||
if e, found := lan.hosts[mac]; found {
|
||||
e.Alias = alias
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (lan *LAN) Get(mac string) (*Endpoint, bool) {
|
||||
lan.Lock()
|
||||
defer lan.Unlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue