mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 10:46:57 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
bf3671465b
commit
4eead7eafa
58 changed files with 2052 additions and 2052 deletions
86
modules/net_recon/net_show_sort.go
Normal file
86
modules/net_recon/net_show_sort.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package net_recon
|
||||
|
||||
import (
|
||||
"github.com/bettercap/bettercap/network"
|
||||
"github.com/bettercap/bettercap/packets"
|
||||
"github.com/bettercap/bettercap/session"
|
||||
)
|
||||
|
||||
type ByAddressSorter []*network.Endpoint
|
||||
|
||||
func (a ByAddressSorter) Len() int { return len(a) }
|
||||
func (a ByAddressSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByAddressSorter) Less(i, j int) bool {
|
||||
if a[i].IpAddressUint32 == a[j].IpAddressUint32 {
|
||||
return a[i].HwAddress < a[j].HwAddress
|
||||
}
|
||||
return a[i].IpAddressUint32 < a[j].IpAddressUint32
|
||||
}
|
||||
|
||||
type ByIpSorter []*network.Endpoint
|
||||
|
||||
func (a ByIpSorter) Len() int { return len(a) }
|
||||
func (a ByIpSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByIpSorter) Less(i, j int) bool {
|
||||
return a[i].IpAddressUint32 < a[j].IpAddressUint32
|
||||
}
|
||||
|
||||
type ByMacSorter []*network.Endpoint
|
||||
|
||||
func (a ByMacSorter) Len() int { return len(a) }
|
||||
func (a ByMacSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByMacSorter) Less(i, j int) bool {
|
||||
return a[i].HwAddress < a[j].HwAddress
|
||||
}
|
||||
|
||||
type BySeenSorter []*network.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.Before(a[j].LastSeen) }
|
||||
|
||||
type BySentSorter []*network.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 {
|
||||
session.I.Queue.Lock()
|
||||
defer session.I.Queue.Unlock()
|
||||
|
||||
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 {
|
||||
aTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found {
|
||||
bTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
return bTraffic.Sent > aTraffic.Sent
|
||||
}
|
||||
|
||||
type ByRcvdSorter []*network.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 {
|
||||
session.I.Queue.Lock()
|
||||
defer session.I.Queue.Unlock()
|
||||
|
||||
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 {
|
||||
aTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found {
|
||||
bTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
return bTraffic.Received > aTraffic.Received
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue