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
}
func getCurrentMacInfo(name string) (result string, err error) {
	currentMacInfo, err := getMacInfo(name, "CurrentMAC")
	if err != nil {
		return
	}
	permanentMac, err := lmf.GetPermanentMac(name)
	if err != nil {
		LogWriter.Err(err.Error())
	}
	permanentMacVendor, err := lmf.FindVendorByMac(permanentMac.String())
	if err != nil {
		if strings.HasPrefix(err.Error(),
			"No vendor found in OuiDb for vendor prefix") {
			permanentMacVendor.Vendor = "Unknown"
		} else {
			return
		}
	}
	if privatevar {
		result = fmt.Sprintf(
			"%s - CurrentMAC: xx:xx:xx:xx:xx:xx (Unknown) Permanent MAC: xx:xx:xx:xx:xx:xx (Unknown)",
			name)
	} else {
		result = fmt.Sprintf("%sPermanent MAC: %s (%s)",
			currentMacInfo, permanentMac, permanentMacVendor.Vendor)
	}
	err = nil
	return
}
Beispiel #3
0
func getCurrentMacInfo(name string) (result string, err error) {
	currentMacInfo, err := getMacInfo(name, "CurrentMAC")
	if err != nil {
		return
	}
	permanentMac, err := lmf.GetPermanentMac(name)
	if err != nil {
		fmt.Println(err)
	}
	permanentMacVendor, err := lmf.FindVendorByMac(permanentMac.String())
	if err != nil {
		if strings.HasPrefix(err.Error(),
			"No vendor found in OuiDb for vendor prefix") {
			permanentMacVendor.Vendor = "Unknown"
		} else {
			return
		}
	}
	result = fmt.Sprintf("%sPermanent MAC:\t%s (%s)",
		currentMacInfo,
		permanentMac, permanentMacVendor.Vendor)
	return
}