mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
new: new by sent and by rcvd net.show sorting methods
This commit is contained in:
parent
b331ca81a2
commit
857c0c7261
2 changed files with 59 additions and 1 deletions
|
@ -2,6 +2,8 @@ package modules
|
|||
|
||||
import (
|
||||
"github.com/evilsocket/bettercap-ng/net"
|
||||
"github.com/evilsocket/bettercap-ng/packets"
|
||||
"github.com/evilsocket/bettercap-ng/session"
|
||||
)
|
||||
|
||||
type ByAddressSorter []*net.Endpoint
|
||||
|
@ -15,3 +17,43 @@ type BySeenSorter []*net.Endpoint
|
|||
func (a BySeenSorter) Len() int { return len(a) }
|
||||
func (a BySeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a BySeenSorter) Less(i, j int) bool { return a[i].LastSeen.After(a[j].LastSeen) }
|
||||
|
||||
type BySentSorter []*net.Endpoint
|
||||
|
||||
func (a BySentSorter) Len() int { return len(a) }
|
||||
func (a BySentSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a BySentSorter) Less(i, j int) bool {
|
||||
var found bool = false
|
||||
var aTraffic *packets.Traffic = nil
|
||||
var bTraffic *packets.Traffic = nil
|
||||
|
||||
if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; found == false {
|
||||
aTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; found == false {
|
||||
bTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
return bTraffic.Sent < aTraffic.Sent
|
||||
}
|
||||
|
||||
type ByRcvdSorter []*net.Endpoint
|
||||
|
||||
func (a ByRcvdSorter) Len() int { return len(a) }
|
||||
func (a ByRcvdSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByRcvdSorter) Less(i, j int) bool {
|
||||
var found bool = false
|
||||
var aTraffic *packets.Traffic = nil
|
||||
var bTraffic *packets.Traffic = nil
|
||||
|
||||
if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; found == false {
|
||||
aTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; found == false {
|
||||
bTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
return bTraffic.Received < aTraffic.Received
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue