misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-02-20 12:38:37 +01:00
commit d9b7d24314
3 changed files with 23 additions and 12 deletions

View file

@ -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 ticker.commands clear; wifi.show

View file

@ -6,6 +6,7 @@ import (
"time"
"github.com/evilsocket/bettercap-ng/log"
"github.com/evilsocket/bettercap-ng/network"
"github.com/evilsocket/bettercap-ng/session"
"github.com/malfunkt/iprange"
@ -80,6 +81,11 @@ func (p *Prober) Start() error {
}
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())
if err != nil {
log.Fatal("%s", err)

View file

@ -10,16 +10,18 @@ type StationLostCallback func(s *Station)
type WiFi struct {
sync.Mutex
iface *Endpoint
stations map[string]*Station
newCb StationNewCallback
lostCb StationLostCallback
Stations map[string]*Station
iface *Endpoint
newCb StationNewCallback
lostCb StationLostCallback
}
func NewWiFi(iface *Endpoint, newcb StationNewCallback, lostcb StationLostCallback) *WiFi {
return &WiFi{
Stations: make(map[string]*Station),
iface: iface,
stations: make(map[string]*Station),
newCb: newcb,
lostCb: lostcb,
}
@ -30,7 +32,7 @@ func (w *WiFi) List() (list []*Station) {
defer w.Unlock()
list = make([]*Station, 0)
for _, t := range w.stations {
for _, t := range w.Stations {
list = append(list, t)
}
return
@ -40,8 +42,8 @@ func (w *WiFi) Remove(mac string) {
w.Lock()
defer w.Unlock()
if s, found := w.stations[mac]; found {
delete(w.stations, mac)
if s, found := w.Stations[mac]; found {
delete(w.Stations, mac)
if w.lostCb != nil {
w.lostCb(s)
}
@ -53,14 +55,14 @@ func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *St
defer w.Unlock()
mac = NormalizeMac(mac)
if station, found := w.stations[mac]; found {
if station, found := w.Stations[mac]; found {
station.LastSeen = time.Now()
station.RSSI = rssi
return station
}
newStation := NewStation(ssid, mac, isAp, channel, rssi)
w.stations[mac] = newStation
w.Stations[mac] = newStation
if w.newCb != nil {
w.newCb(newStation)
@ -74,11 +76,11 @@ func (w *WiFi) Get(mac string) (*Station, bool) {
defer w.Unlock()
mac = NormalizeMac(mac)
station, found := w.stations[mac]
station, found := w.Stations[mac]
return station, found
}
func (w *WiFi) Clear() error {
w.stations = make(map[string]*Station)
w.Stations = make(map[string]*Station)
return nil
}