mosers
/
eaas-vde-proxy
Archiviert
1
0
Fork 0

Randomize new MAC [Close #15]

main
Simon Moser vor 3 Jahren
Ursprung 4eca9d5ce8
Commit 2a7a3cc8e5
Signiert von: mosers
GPG-Schlüssel-ID: 96B3365A234B500C

@ -28,7 +28,7 @@ func main() {
oldip := flag.String("oldip", "", "IP before change") oldip := flag.String("oldip", "", "IP before change")
newip := flag.String("newip", "10.0.0.15", "IP after change") newip := flag.String("newip", "10.0.0.15", "IP after change")
oldmac := flag.String("oldmac", "", "MAC before change") oldmac := flag.String("oldmac", "", "MAC before change")
newmac := flag.String("newmac", "52:54:00:12:34:aa", "MAC after change") newmac := flag.String("newmac", "", "MAC after change")
passthrough := flag.Bool("passthrough", false, "Whether to pass every traffic through") passthrough := flag.Bool("passthrough", false, "Whether to pass every traffic through")
proxy := flag.String("proxy", "1", "Number of the proxy switch") proxy := flag.String("proxy", "1", "Number of the proxy switch")
pidfile := flag.String("pidfile", "", "Location to write the pid to") pidfile := flag.String("pidfile", "", "Location to write the pid to")
@ -36,7 +36,7 @@ func main() {
flag.Parse() flag.Parse()
log.SetLevel(log.Level(*logLvl)) log.SetLevel(log.Level(*logLvl))
OldMac, _ = net.ParseMAC(*oldmac) OldMac, _ = net.ParseMAC(*oldmac)
NewMac, _ = net.ParseMAC(*newmac) NewMac = util.GenerateMac(*newmac)
OldIP = net.ParseIP(*oldip).To4() OldIP = net.ParseIP(*oldip).To4()
NewIP = net.ParseIP(*newip).To4() NewIP = net.ParseIP(*newip).To4()
log.SetFormatter(&log.TextFormatter{ log.SetFormatter(&log.TextFormatter{

Binäre Datei nicht angezeigt.

@ -1,11 +1,13 @@
package util package util
import ( import (
"crypto/rand"
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
"github.com/google/gopacket/pcapgo" "github.com/google/gopacket/pcapgo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"net"
"os" "os"
"strconv" "strconv"
) )
@ -38,7 +40,25 @@ func WritePIDFile(filename string) {
if filename == "" { if filename == "" {
return return
} }
if err := ioutil.WriteFile(filename, []byte(strconv.Itoa(os.Getpid())), 0644); err != nil { if err := ioutil.WriteFile(filename, []byte(strconv.Itoa(os.Getpid()) + "\n"), 0644); err != nil {
log.Errorf("Error writing PID file %s", filename) log.Errorf("Error writing PID file %s", filename)
} }
} }
func GenerateMac(customMAC string) net.HardwareAddr {
if customMAC != "" {
ret, _ := net.ParseMAC("52:54:00:12:34:aa")
return ret
}
buf := make([]byte, 6)
var mac net.HardwareAddr
if _, err := rand.Read(buf); err != nil {
log.Error("Error generating random mac")
ret, _ := net.ParseMAC("52:54:00:12:34:aa")
return ret
}
// Set local bit, ensure unicast address
buf[0] = (buf[0] | 2) & 0xfe
mac = append(mac, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5])
return mac
}