fix: fixed packets queue stats

This commit is contained in:
evilsocket 2018-01-13 18:48:52 +01:00
commit 656b633023
3 changed files with 19 additions and 11 deletions

View file

@ -16,6 +16,7 @@ import (
type Activity struct { type Activity struct {
IP net.IP IP net.IP
MAC net.HardwareAddr MAC net.HardwareAddr
Source bool
} }
type Queue struct { type Queue struct {
@ -96,6 +97,7 @@ func (q *Queue) worker() {
q.Activities <- Activity{ q.Activities <- Activity{
IP: ip4.SrcIP, IP: ip4.SrcIP,
MAC: eth.SrcMAC, MAC: eth.SrcMAC,
Source: true,
} }
} }
@ -103,6 +105,7 @@ func (q *Queue) worker() {
q.Activities <- Activity{ q.Activities <- Activity{
IP: ip4.DstIP, IP: ip4.DstIP,
MAC: eth.SrcMAC, MAC: eth.SrcMAC,
Source: false,
} }
} }
} }

View file

@ -10,6 +10,7 @@ import (
"sort" "sort"
"strings" "strings"
"syscall" "syscall"
"time"
"github.com/chzyer/readline" "github.com/chzyer/readline"
@ -231,9 +232,15 @@ func (s *Session) Start() error {
// keep reading network events in order to add / update endpoints // keep reading network events in order to add / update endpoints
go func() { go func() {
for event := range s.Queue.Activities { for event := range s.Queue.Activities {
if event.Source == true {
addr := event.IP.String() addr := event.IP.String()
mac := event.MAC.String() mac := event.MAC.String()
s.Targets.AddIfNotExist(addr, mac)
existing := s.Targets.AddIfNotExist(addr, mac)
if existing != nil {
existing.LastSeen = time.Now()
}
}
if s.Active == false { if s.Active == false {
return return

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"sort" "sort"
"sync" "sync"
"time"
"github.com/evilsocket/bettercap-ng/core" "github.com/evilsocket/bettercap-ng/core"
"github.com/evilsocket/bettercap-ng/net" "github.com/evilsocket/bettercap-ng/net"
@ -64,7 +63,6 @@ func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
} }
if t, found := tp.Targets[mac]; found { if t, found := tp.Targets[mac]; found {
t.LastSeen = time.Now()
return t return t
} }