mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
9da2df981c
commit
d9b7d24314
3 changed files with 23 additions and 12 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# let's add some api :D
|
||||||
|
include caplets/rest-api.cap
|
||||||
|
|
||||||
set $ {by}{fw}{env.iface.name}{reset} {bold}» {reset}
|
set $ {by}{fw}{env.iface.name}{reset} {bold}» {reset}
|
||||||
set ticker.commands clear; wifi.show
|
set ticker.commands clear; wifi.show
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evilsocket/bettercap-ng/log"
|
"github.com/evilsocket/bettercap-ng/log"
|
||||||
|
"github.com/evilsocket/bettercap-ng/network"
|
||||||
"github.com/evilsocket/bettercap-ng/session"
|
"github.com/evilsocket/bettercap-ng/session"
|
||||||
|
|
||||||
"github.com/malfunkt/iprange"
|
"github.com/malfunkt/iprange"
|
||||||
|
@ -80,6 +81,11 @@ func (p *Prober) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.SetRunning(true, func() {
|
return p.SetRunning(true, func() {
|
||||||
|
if p.Session.Interface.IpAddress == network.MonitorModeAddress {
|
||||||
|
log.Info("Interface is in monitor mode, skipping net.probe")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
list, err := iprange.Parse(p.Session.Interface.CIDR())
|
list, err := iprange.Parse(p.Session.Interface.CIDR())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("%s", err)
|
log.Fatal("%s", err)
|
||||||
|
|
|
@ -10,16 +10,18 @@ type StationLostCallback func(s *Station)
|
||||||
|
|
||||||
type WiFi struct {
|
type WiFi struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
iface *Endpoint
|
|
||||||
stations map[string]*Station
|
Stations map[string]*Station
|
||||||
newCb StationNewCallback
|
|
||||||
lostCb StationLostCallback
|
iface *Endpoint
|
||||||
|
newCb StationNewCallback
|
||||||
|
lostCb StationLostCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWiFi(iface *Endpoint, newcb StationNewCallback, lostcb StationLostCallback) *WiFi {
|
func NewWiFi(iface *Endpoint, newcb StationNewCallback, lostcb StationLostCallback) *WiFi {
|
||||||
return &WiFi{
|
return &WiFi{
|
||||||
|
Stations: make(map[string]*Station),
|
||||||
iface: iface,
|
iface: iface,
|
||||||
stations: make(map[string]*Station),
|
|
||||||
newCb: newcb,
|
newCb: newcb,
|
||||||
lostCb: lostcb,
|
lostCb: lostcb,
|
||||||
}
|
}
|
||||||
|
@ -30,7 +32,7 @@ func (w *WiFi) List() (list []*Station) {
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
|
|
||||||
list = make([]*Station, 0)
|
list = make([]*Station, 0)
|
||||||
for _, t := range w.stations {
|
for _, t := range w.Stations {
|
||||||
list = append(list, t)
|
list = append(list, t)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -40,8 +42,8 @@ func (w *WiFi) Remove(mac string) {
|
||||||
w.Lock()
|
w.Lock()
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
|
|
||||||
if s, found := w.stations[mac]; found {
|
if s, found := w.Stations[mac]; found {
|
||||||
delete(w.stations, mac)
|
delete(w.Stations, mac)
|
||||||
if w.lostCb != nil {
|
if w.lostCb != nil {
|
||||||
w.lostCb(s)
|
w.lostCb(s)
|
||||||
}
|
}
|
||||||
|
@ -53,14 +55,14 @@ func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *St
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
|
|
||||||
mac = NormalizeMac(mac)
|
mac = NormalizeMac(mac)
|
||||||
if station, found := w.stations[mac]; found {
|
if station, found := w.Stations[mac]; found {
|
||||||
station.LastSeen = time.Now()
|
station.LastSeen = time.Now()
|
||||||
station.RSSI = rssi
|
station.RSSI = rssi
|
||||||
return station
|
return station
|
||||||
}
|
}
|
||||||
|
|
||||||
newStation := NewStation(ssid, mac, isAp, channel, rssi)
|
newStation := NewStation(ssid, mac, isAp, channel, rssi)
|
||||||
w.stations[mac] = newStation
|
w.Stations[mac] = newStation
|
||||||
|
|
||||||
if w.newCb != nil {
|
if w.newCb != nil {
|
||||||
w.newCb(newStation)
|
w.newCb(newStation)
|
||||||
|
@ -74,11 +76,11 @@ func (w *WiFi) Get(mac string) (*Station, bool) {
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
|
|
||||||
mac = NormalizeMac(mac)
|
mac = NormalizeMac(mac)
|
||||||
station, found := w.stations[mac]
|
station, found := w.Stations[mac]
|
||||||
return station, found
|
return station, found
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WiFi) Clear() error {
|
func (w *WiFi) Clear() error {
|
||||||
w.stations = make(map[string]*Station)
|
w.Stations = make(map[string]*Station)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue