func revertMac(name string) (err error) {
	currentMacInfo, err := getCurrentMacInfo(name)
	if err != nil {
		return
	}
	LogWriter.Info(currentMacInfo)
	permMac, err := lmf.GetPermanentMac(name)
	if err != nil {
		return
	}
	err = lmf.RevertMac(name)
	if err != nil {
		return
	}
	newMac, err := lmf.GetCurrentMac(name)
	if err != nil {
		return
	}
	if lmf.CompareMacs(permMac, newMac) {
		newMac, err2 := getMacInfo(name, "New MAC")
		if err2 != nil {
			err = err2
			return
		}
		LogWriter.Info(newMac)
	}
	return
}
Esempio n. 2
0
func spoofMac(name string, mac string) (err error) {
	currentMacInfo, err := getCurrentMacInfo(name)
	if err != nil {
		return
	}
	fmt.Println(currentMacInfo)
	pMac, err := net.ParseMAC(mac)
	if err != nil {
		return
	}
	err = lmf.SetMac(name, mac)
	if err != nil {
		return
	}
	newMac, err := lmf.GetCurrentMac(name)
	if err != nil {
		return
	}
	changed := lmf.CompareMacs(pMac, newMac)
	if changed {
		newMacInfo, err2 := getMacInfo(name, "New MAC")
		if err2 != nil {
			err = err2
			return
		}
		fmt.Printf(newMacInfo)
	}
	return
}
func getMacInfo(name string, macType string) (result string, err error) {
	newMac, err := lmf.GetCurrentMac(name)
	if err != nil {
		return
	}
	newMacVendor, err := lmf.FindVendorByMac(newMac.String())
	if err != nil {
		if err == err.(lmf.NoVendorError) {
			newMacVendor.Vendor = "Unknown"
			err = nil
		} else {
			return
		}
	}
	result = fmt.Sprintf("%s - %s: %s (%s) ",
		name, macType, newMac, newMacVendor.Vendor)
	return
}