mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 10:46:57 -07:00
new: ble.show shows device names if available for at least one of the devices
This commit is contained in:
parent
3e7aa68184
commit
a72801f9b5
2 changed files with 46 additions and 14 deletions
|
@ -19,7 +19,7 @@ var (
|
|||
blePresentInterval = time.Duration(30) * time.Second
|
||||
)
|
||||
|
||||
func (mod *BLERecon) getRow(dev *network.BLEDevice) []string {
|
||||
func (mod *BLERecon) getRow(dev *network.BLEDevice, withName bool) []string {
|
||||
rssi := network.ColorRSSI(dev.RSSI)
|
||||
address := network.NormalizeMac(dev.Device.ID())
|
||||
vendor := tui.Dim(ops.Ternary(dev.Vendor == "", dev.Advertisement.Company, dev.Vendor).(string))
|
||||
|
@ -34,13 +34,25 @@ func (mod *BLERecon) getRow(dev *network.BLEDevice) []string {
|
|||
address = tui.Dim(address)
|
||||
}
|
||||
|
||||
return []string{
|
||||
rssi,
|
||||
address,
|
||||
vendor,
|
||||
dev.Advertisement.Flags.String(),
|
||||
isConnectable,
|
||||
lastSeen,
|
||||
if withName {
|
||||
return []string{
|
||||
rssi,
|
||||
address,
|
||||
dev.Name(),
|
||||
vendor,
|
||||
dev.Advertisement.Flags.String(),
|
||||
isConnectable,
|
||||
lastSeen,
|
||||
}
|
||||
} else {
|
||||
return []string{
|
||||
rssi,
|
||||
address,
|
||||
vendor,
|
||||
dev.Advertisement.Flags.String(),
|
||||
isConnectable,
|
||||
lastSeen,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,15 +109,20 @@ func (mod *BLERecon) doSelection() (err error, devices []*network.BLEDevice) {
|
|||
return
|
||||
}
|
||||
|
||||
func (mod *BLERecon) colNames() []string {
|
||||
func (mod *BLERecon) colNames(withName bool) []string {
|
||||
colNames := []string{"RSSI", "MAC", "Vendor", "Flags", "Connect", "Seen"}
|
||||
seenIdx := 5
|
||||
if withName {
|
||||
colNames = []string{"RSSI", "MAC", "Name", "Vendor", "Flags", "Connect", "Seen"}
|
||||
seenIdx = 6
|
||||
}
|
||||
switch mod.selector.SortField {
|
||||
case "rssi":
|
||||
colNames[0] += " " + mod.selector.SortSymbol
|
||||
case "mac":
|
||||
colNames[1] += " " + mod.selector.SortSymbol
|
||||
case "seen":
|
||||
colNames[5] += " " + mod.selector.SortSymbol
|
||||
colNames[seenIdx] += " " + mod.selector.SortSymbol
|
||||
}
|
||||
return colNames
|
||||
}
|
||||
|
@ -116,13 +133,21 @@ func (mod *BLERecon) Show() error {
|
|||
return err
|
||||
}
|
||||
|
||||
hasName := false
|
||||
for _, dev := range devices {
|
||||
if dev.Name() != "" {
|
||||
hasName = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
rows := make([][]string, 0)
|
||||
for _, dev := range devices {
|
||||
rows = append(rows, mod.getRow(dev))
|
||||
rows = append(rows, mod.getRow(dev, hasName))
|
||||
}
|
||||
|
||||
if len(rows) > 0 {
|
||||
tui.Table(os.Stdout, mod.colNames(), rows)
|
||||
tui.Table(os.Stdout, mod.colNames(hasName), rows)
|
||||
mod.Session.Refresh()
|
||||
}
|
||||
|
||||
|
|
|
@ -40,14 +40,21 @@ func NewBLEDevice(p gatt.Peripheral, a *gatt.Advertisement, rssi int) *BLEDevice
|
|||
}
|
||||
}
|
||||
|
||||
func (d *BLEDevice) Name() string {
|
||||
name := d.Device.Name()
|
||||
if name == "" && d.Advertisement != nil {
|
||||
name = d.Advertisement.LocalName
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func (d *BLEDevice) MarshalJSON() ([]byte, error) {
|
||||
doc := bleDeviceJSON{
|
||||
LastSeen: d.LastSeen,
|
||||
Name: d.Device.Name(),
|
||||
Name: d.Name(),
|
||||
MAC: d.Device.ID(),
|
||||
Vendor: d.Vendor,
|
||||
RSSI: d.RSSI,
|
||||
}
|
||||
|
||||
return json.Marshal(doc)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue