mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
new: wifi.show and net.show columns are now decorated according to sorting
This commit is contained in:
parent
58738b7723
commit
2fe9a2af2f
2 changed files with 88 additions and 20 deletions
|
@ -179,6 +179,36 @@ func (d *Discovery) doSelection(arg string) (err error, targets []*network.Endpo
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Discovery) colNames(hasMeta bool) []string {
|
||||||
|
colNames := []string{"IP", "MAC", "Name", "Vendor", "Sent", "Recvd", "Last Seen"}
|
||||||
|
if hasMeta {
|
||||||
|
colNames = append(colNames, "Meta")
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := tui.Blue("▾")
|
||||||
|
if d.selector.Sort == "asc" {
|
||||||
|
dir = tui.Blue("▴")
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.selector.SortBy == "" {
|
||||||
|
d.selector.SortBy = "ip"
|
||||||
|
}
|
||||||
|
switch d.selector.SortBy {
|
||||||
|
case "mac":
|
||||||
|
colNames[1] += " " + dir
|
||||||
|
case "sent":
|
||||||
|
colNames[4] += " " + dir
|
||||||
|
case "rcvd":
|
||||||
|
colNames[5] += " " + dir
|
||||||
|
case "seen":
|
||||||
|
colNames[6] += " " + dir
|
||||||
|
case "ip":
|
||||||
|
colNames[0] += " " + dir
|
||||||
|
}
|
||||||
|
|
||||||
|
return colNames
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Discovery) Show(arg string) (err error) {
|
func (d *Discovery) Show(arg string) (err error) {
|
||||||
var targets []*network.Endpoint
|
var targets []*network.Endpoint
|
||||||
if err, targets = d.doSelection(arg); err != nil {
|
if err, targets = d.doSelection(arg); err != nil {
|
||||||
|
@ -205,12 +235,8 @@ func (d *Discovery) Show(arg string) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
padCols := []string{"", "", "", "", "", "", ""}
|
colNames := d.colNames(hasMeta)
|
||||||
colNames := []string{"IP", "MAC", "Name", "Vendor", "Sent", "Recvd", "Last Seen"}
|
padCols := make([]string, len(colNames))
|
||||||
if hasMeta {
|
|
||||||
padCols = append(padCols, "")
|
|
||||||
colNames = append(colNames, "Meta")
|
|
||||||
}
|
|
||||||
|
|
||||||
rows := make([][]string, 0)
|
rows := make([][]string, 0)
|
||||||
for i, t := range targets {
|
for i, t := range targets {
|
||||||
|
|
|
@ -189,6 +189,61 @@ func (w *WiFiModule) doSelection() (err error, stations []*network.Station) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WiFiModule) colDecorate(colNames []string, name string, dir string) {
|
||||||
|
for i, c := range colNames {
|
||||||
|
if c == name {
|
||||||
|
colNames[i] += " " + dir
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WiFiModule) colNames(nrows int) []string {
|
||||||
|
columns := []string(nil)
|
||||||
|
|
||||||
|
if !w.isApSelected() {
|
||||||
|
columns = []string{"RSSI", "BSSID", "SSID", "Encryption", "Channel", "Clients", "Sent", "Recvd", "Last Seen"}
|
||||||
|
} else if nrows > 0 {
|
||||||
|
columns = []string{"RSSI", "MAC", "Channel", "Sent", "Received", "Last Seen"}
|
||||||
|
fmt.Printf("\n%s clients:\n", w.ap.HwAddress)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\nNo authenticated clients detected for %s.\n", w.ap.HwAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
if columns != nil {
|
||||||
|
dir := tui.Blue("▾")
|
||||||
|
if w.selector.Sort == "asc" {
|
||||||
|
dir = tui.Blue("▴")
|
||||||
|
}
|
||||||
|
|
||||||
|
if w.selector.SortBy == "" {
|
||||||
|
w.selector.SortBy = "rssi"
|
||||||
|
}
|
||||||
|
switch w.selector.SortBy {
|
||||||
|
case "seen":
|
||||||
|
w.colDecorate(columns, "Last Seen", dir)
|
||||||
|
case "essid":
|
||||||
|
w.colDecorate(columns, "SSID", dir)
|
||||||
|
case "bssid":
|
||||||
|
w.colDecorate(columns, "BSSID", dir)
|
||||||
|
case "channel":
|
||||||
|
w.colDecorate(columns, "Channel", dir)
|
||||||
|
case "clients":
|
||||||
|
w.colDecorate(columns, "Clients", dir)
|
||||||
|
case "encryption":
|
||||||
|
w.colDecorate(columns, "Encryption", dir)
|
||||||
|
case "sent":
|
||||||
|
w.colDecorate(columns, "Sent", dir)
|
||||||
|
case "rcvd":
|
||||||
|
w.colDecorate(columns, "Recvd", dir)
|
||||||
|
case "rssi":
|
||||||
|
w.colDecorate(columns, "RSSI", dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return columns
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WiFiModule) Show() (err error) {
|
func (w *WiFiModule) Show() (err error) {
|
||||||
var stations []*network.Station
|
var stations []*network.Station
|
||||||
if err, stations = w.doSelection(); err != nil {
|
if err, stations = w.doSelection(); err != nil {
|
||||||
|
@ -202,21 +257,8 @@ func (w *WiFiModule) Show() (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nrows := len(rows)
|
nrows := len(rows)
|
||||||
|
|
||||||
columns := []string{"RSSI", "BSSID", "SSID" /* "Vendor", */, "Encryption", "Channel", "Clients", "Sent", "Recvd", "Last Seen"}
|
|
||||||
if w.isApSelected() {
|
|
||||||
// these are clients
|
|
||||||
columns = []string{"RSSI", "MAC" /* "Vendor", */, "Channel", "Sent", "Received", "Last Seen"}
|
|
||||||
|
|
||||||
if nrows == 0 {
|
|
||||||
fmt.Printf("\nNo authenticated clients detected for %s.\n", w.ap.HwAddress)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("\n%s clients:\n", w.ap.HwAddress)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if nrows > 0 {
|
if nrows > 0 {
|
||||||
tui.Table(os.Stdout, columns, rows)
|
tui.Table(os.Stdout, w.colNames(nrows), rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Session.Queue.Stats.RLock()
|
w.Session.Queue.Stats.RLock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue