Use the MacChanger struct's originalMac field to determine if the module has already been configured

This goal of this commit is to provide a simple way to deal with the
original mac resotation issue I was facing where the MacChanger struct
was being overwritten if called twice/more than once. This should lock
up users from doing that but provide them a way around it ( not locking
them into an original mac address when I could want to change it
outside my bettercap session) with a consistent-ish experience until I
figure something else out. Or someone else does.

It’s also late and I need to be studying for my windows administration
class midterm.

It’s supposed to be an Advanced Windows Administration class. But it’s
not.

Anyways. I’m sure this commit isn’t perfect. But. What code is? 😂
This commit is contained in:
Kent Gruber 2018-02-28 00:25:07 -05:00
commit 69d5cc574f

View file

@ -1,6 +1,7 @@
package modules
import (
"errors"
"fmt"
"net"
"runtime"
@ -64,6 +65,10 @@ func (mc *MacChanger) Author() string {
func (mc *MacChanger) Configure() (err error) {
var changeTo string
if mc.originalMac != nil {
return errors.New("mac.changer has already been configured, you will need to turn it off to re-configure")
}
if err, mc.iface = mc.StringParam("mac.changer.iface"); err != nil {
return err
}
@ -119,6 +124,9 @@ func (mc *MacChanger) Stop() error {
return err
}
// the the module can now be reconfigured
mc.originalMac = nil
return mc.SetRunning(false, func() {
log.Info("Interface mac address restored to %s", core.Bold(mc.originalMac.String()))
})