fix: bring interface down for mac.changer module

This commit is contained in:
Simone Margaritelli 2024-08-18 15:34:02 +02:00
parent 08da91ed5c
commit d8e11287c6

View file

@ -82,6 +82,11 @@ func (mod *MacChanger) Configure() (err error) {
} }
func (mod *MacChanger) setMac(mac net.HardwareAddr) error { func (mod *MacChanger) setMac(mac net.HardwareAddr) error {
core.Exec("ifconfig", []string{mod.iface, "down"})
defer func() {
core.Exec("ifconfig", []string{mod.iface, "up"})
}()
var args []string var args []string
os := runtime.GOOS os := runtime.GOOS
@ -90,12 +95,14 @@ func (mod *MacChanger) setMac(mac net.HardwareAddr) error {
} else if os == "linux" || os == "android" { } else if os == "linux" || os == "android" {
args = []string{mod.iface, "hw", "ether", mac.String()} args = []string{mod.iface, "hw", "ether", mac.String()}
} else { } else {
return fmt.Errorf("OS %s is not supported by mac.changer module.", os) return fmt.Errorf("%s is not supported by this module", os)
} }
_, err := core.Exec("ifconfig", args) out, err := core.Exec("ifconfig", args)
if err == nil { if err == nil {
mod.Session.Interface.HW = mac mod.Session.Interface.HW = mac
} else {
mod.Warning("%v: %s", err, out)
} }
return err return err