mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
new: new wifi.region and wifi.txpower parameters
This commit is contained in:
parent
2446cde2e1
commit
345c1f5d45
2 changed files with 52 additions and 6 deletions
|
@ -28,6 +28,8 @@ type WiFiModule struct {
|
||||||
|
|
||||||
handle *pcap.Handle
|
handle *pcap.Handle
|
||||||
source string
|
source string
|
||||||
|
region string
|
||||||
|
txPower int
|
||||||
minRSSI int
|
minRSSI int
|
||||||
channel int
|
channel int
|
||||||
hopPeriod time.Duration
|
hopPeriod time.Duration
|
||||||
|
@ -169,6 +171,15 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
||||||
|
|
||||||
mod.AddHandler(assoc)
|
mod.AddHandler(assoc)
|
||||||
|
|
||||||
|
mod.AddParam(session.NewStringParameter("wifi.region",
|
||||||
|
"BO",
|
||||||
|
"",
|
||||||
|
"Set the WiFi region to this value before activating the interface."))
|
||||||
|
|
||||||
|
mod.AddParam(session.NewIntParameter("wifi.txpower",
|
||||||
|
"30",
|
||||||
|
"Set WiFi transmission power to this value before activating the interface."))
|
||||||
|
|
||||||
mod.AddParam(session.NewStringParameter("wifi.assoc.skip",
|
mod.AddParam(session.NewStringParameter("wifi.assoc.skip",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
@ -310,7 +321,13 @@ func (mod *WiFiModule) Configure() error {
|
||||||
var hopPeriod int
|
var hopPeriod int
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err, mod.source = mod.StringParam("wifi.source.file"); err != nil {
|
if err, mod.region = mod.StringParam("wifi.region"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err, mod.txPower = mod.IntParam("wifi.txpower"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err, mod.source = mod.StringParam("wifi.source.file"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err, mod.minRSSI = mod.IntParam("wifi.rssi.min"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,17 +339,28 @@ func (mod *WiFiModule) Configure() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err, mod.minRSSI = mod.IntParam("wifi.rssi.min"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ifName := mod.Session.Interface.Name()
|
ifName := mod.Session.Interface.Name()
|
||||||
|
|
||||||
if mod.source != "" {
|
if mod.source != "" {
|
||||||
if mod.handle, err = pcap.OpenOffline(mod.source); err != nil {
|
if mod.handle, err = pcap.OpenOffline(mod.source); err != nil {
|
||||||
return fmt.Errorf("error while opening file %s: %s", mod.source, err)
|
return fmt.Errorf("error while opening file %s: %s", mod.source, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if mod.region != "" {
|
||||||
|
if err := network.SetWiFiRegion(mod.region); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
mod.Info("WiFi region set to '%s'", mod.region)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mod.txPower > 0 {
|
||||||
|
if err := network.SetInterfaceTxPower(ifName, mod.txPower); err != nil {
|
||||||
|
mod.Warning("could not set interface %s txpower to %d, 'Set Tx Power' requests not supported", ifName, mod.txPower)
|
||||||
|
} else {
|
||||||
|
mod.Info("interface %s txpower set to %d", ifName, mod.txPower)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for retry := 0; ; retry++ {
|
for retry := 0; ; retry++ {
|
||||||
ihandle, err := pcap.NewInactiveHandle(ifName)
|
ihandle, err := pcap.NewInactiveHandle(ifName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -264,6 +264,15 @@ func FindInterface(name string) (*Endpoint, error) {
|
||||||
return nil, ErrNoIfaces
|
return nil, ErrNoIfaces
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetWiFiRegion(region string) error {
|
||||||
|
if out, err := core.Exec("iw", []string{"reg", "set", region}); err != nil {
|
||||||
|
return err
|
||||||
|
} else if out != "" {
|
||||||
|
return fmt.Errorf("unexpected output while setting WiFi region %s: %s", region, out)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func ActivateInterface(name string) error {
|
func ActivateInterface(name string) error {
|
||||||
if out, err := core.Exec("ifconfig", []string{name, "up"}); err != nil {
|
if out, err := core.Exec("ifconfig", []string{name, "up"}); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -273,6 +282,15 @@ func ActivateInterface(name string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetInterfaceTxPower(name string, txpower int) error {
|
||||||
|
if out, err := core.ExecSilent("iwconfig", []string{name, "txpower", fmt.Sprintf("%d", txpower)}); err != nil {
|
||||||
|
return err
|
||||||
|
} else if out != "" {
|
||||||
|
return fmt.Errorf("unexpected output while setting txpower to %d for interface %s: %s", txpower, name, out)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func GatewayProvidedByUser(iface *Endpoint, gateway string) (*Endpoint, error) {
|
func GatewayProvidedByUser(iface *Endpoint, gateway string) (*Endpoint, error) {
|
||||||
Debug("GatewayProvidedByUser(%s) [cmd=%v opts=%v parser=%v]", gateway, IPv4RouteCmd, IPv4RouteCmdOpts, IPv4RouteParser)
|
Debug("GatewayProvidedByUser(%s) [cmd=%v opts=%v parser=%v]", gateway, IPv4RouteCmd, IPv4RouteCmdOpts, IPv4RouteParser)
|
||||||
if IPv4Validator.MatchString(gateway) {
|
if IPv4Validator.MatchString(gateway) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue