MCPcopy
hub / github.com/bettercap/bettercap / setMac

Method setMac

modules/mac_changer/mac_changer.go:84–109  ·  view source on GitHub ↗
(mac net.HardwareAddr)

Source from the content-addressed store, hash-verified

82}
83
84func (mod *MacChanger) setMac(mac net.HardwareAddr) error {
85 core.Exec("ifconfig", []string{mod.iface, "down"})
86 defer func() {
87 core.Exec("ifconfig", []string{mod.iface, "up"})
88 }()
89
90 var args []string
91
92 os := runtime.GOOS
93 if strings.Contains(os, "bsd") || os == "darwin" {
94 args = []string{mod.iface, "ether", mac.String()}
95 } else if os == "linux" || os == "android" {
96 args = []string{mod.iface, "hw", "ether", mac.String()}
97 } else {
98 return fmt.Errorf("%s is not supported by this module", os)
99 }
100
101 out, err := core.Exec("ifconfig", args)
102 if err == nil {
103 mod.Session.Interface.HW = mac
104 } else {
105 mod.Warning("%v: %s", err, out)
106 }
107
108 return err
109}
110
111func (mod *MacChanger) Start() error {
112 if mod.Running() {

Callers 2

StartMethod · 0.95
StopMethod · 0.95

Calls 3

ExecFunction · 0.92
StringMethod · 0.45
WarningMethod · 0.45

Tested by

no test coverage detected