mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
new: added new Meta field to Endpoint objects (closes #66)
This commit is contained in:
parent
f243262200
commit
02d414107e
3 changed files with 48 additions and 3 deletions
|
@ -41,7 +41,7 @@ func (s EventsStream) viewApEvent(e session.Event) {
|
|||
fmt.Printf("[%s] [%s] %s\n",
|
||||
e.Time.Format(eventTimeFormat),
|
||||
core.Green(e.Tag),
|
||||
ap)
|
||||
ap.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ func (s EventsStream) viewEndpointEvent(e session.Event) {
|
|||
fmt.Printf("[%s] [%s] %s\n",
|
||||
e.Time.Format(eventTimeFormat),
|
||||
core.Green(e.Tag),
|
||||
t)
|
||||
t.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ type Endpoint struct {
|
|||
ResolvedCallback OnHostResolvedCallback `json:"-"`
|
||||
FirstSeen time.Time `json:"first_seen"`
|
||||
LastSeen time.Time `json:"last_seen"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
func ip2int(ip net.IP) uint32 {
|
||||
|
@ -56,6 +57,7 @@ func NewEndpointNoResolve(ip, mac, name string, bits uint32) *Endpoint {
|
|||
ResolvedCallback: nil,
|
||||
FirstSeen: now,
|
||||
LastSeen: now,
|
||||
Meta: NewMeta(),
|
||||
}
|
||||
|
||||
_, netw, _ := net.ParseCIDR(e.CIDR())
|
||||
|
@ -66,7 +68,6 @@ func NewEndpointNoResolve(ip, mac, name string, bits uint32) *Endpoint {
|
|||
|
||||
func NewEndpoint(ip, mac string) *Endpoint {
|
||||
e := NewEndpointNoResolve(ip, mac, "", 0)
|
||||
|
||||
// start resolver goroutine
|
||||
go func() {
|
||||
if names, err := net.LookupAddr(e.IpAddress); err == nil && len(names) > 0 {
|
||||
|
|
44
network/meta.go
Normal file
44
network/meta.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
sync.Mutex
|
||||
m map[string]interface{}
|
||||
}
|
||||
|
||||
// we want to protect concurrent access to the Meta
|
||||
// object so the m field needs to be unexported, this
|
||||
// is to have it in JSON regardless.
|
||||
type metaJSON struct {
|
||||
Values map[string]interface{} `json:"values"`
|
||||
}
|
||||
|
||||
func NewMeta() *Meta {
|
||||
return &Meta{
|
||||
m: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Meta) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(metaJSON{Values: m.m})
|
||||
}
|
||||
|
||||
func (m *Meta) Set(name string, value interface{}) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
m.m[name] = value
|
||||
}
|
||||
|
||||
func (m *Meta) Get(name string) interface{} {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
if v, found := m.m[name]; found == true {
|
||||
return v
|
||||
}
|
||||
return ""
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue