-
Notifications
You must be signed in to change notification settings - Fork 4
/
mac-changer.go
44 lines (36 loc) · 992 Bytes
/
mac-changer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
//usage: go run mac-changer.go -i <interface> -m <new-mac>
//example: go run mac-changer.go -i eth0 -m 00:11:22:33:44:55:66
import (
"flag"
"log"
"os"
"os/exec"
)
func executeCommand(command string, argsArray []string) (err error) {
args := argsArray
// create object
cmdObj := exec.Command(command, args...)
// stdout to display the output on the screen
cmdObj.Stdout = os.Stdout
// process errors
cmdObj.Stderr = os.Stderr
// stdin to add input commands
cmdObj.Stdin = os.Stdin
// run the command
err = cmdObj.Run()
if err != nil {
log.Fatal(err)
return
}
return nil
}
func main() {
iface := flag.String("i", "eth0", "Interface to change MAC address")
newmac := flag.String("m", "", "Type new MAC address")
flag.Parse()
command := "sudo"
executeCommand(command, []string{"ifconfig", *iface, "down"})
executeCommand(command, []string{"ifconfig", *iface, "hw", "ether", *newmac})
executeCommand(command, []string{"ifconfig", *iface, "up"})
}