Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect MAC address #33

Open
Rage997 opened this issue Sep 17, 2022 · 2 comments
Open

Incorrect MAC address #33

Rage997 opened this issue Sep 17, 2022 · 2 comments

Comments

@Rage997
Copy link

Rage997 commented Sep 17, 2022

Hi all,

On my machine (2019 Mac Book Pro running Mojave) the following code:

extern crate mac_address;

use mac_address::get_mac_address;

fn main() {
    match get_mac_address() {
        Ok(Some(ma)) => {
            println!("MAC addr = {}", ma);
            println!("bytes = {:?}", ma.bytes());
        }
        Ok(None) => println!("No MAC address found."),
        Err(e) => println!("{:?}", e),
    }
}

retrieves an incorrect MAC address. Any idea why?
~

@repnop
Copy link
Owner

repnop commented Sep 20, 2022

unfortunately I don't have access to that kind of machine, so I'll need more context. what is the "incorrect MAC address" and why do you believe it to be incorrect?

@Rage997
Copy link
Author

Rage997 commented Oct 1, 2022

Let me elabatore. I get the loopback address 00-00-00-00-00-00 which is uninteresting (not incorrect, but uninteresting). People are generally interested in the network adapter (en0) mac address

I am currently writing a small rust library to generate a serial number linked to hardware-specific identifiers such as mac address. On my code, this is how I get the MAC to address, in case you might find it helpful:

#[cfg(target_os = "macos")]
pub fn get() {
    // On mac, you can get all the mac addresses by running /sbin/ifconfig | grep ether
    
	let output = Command::new("/sbin/ifconfig")
        .args(["en0"])
	.output()
	.expect("Failed to retrieve hardware information");

    assert!(output.status.success());
	let tmp =  String::from_utf8(output.stdout)
		.expect("Found invalid UTF-8");
	match tmp
		.lines()
		.find(|l| l.contains("ether"))// find the line containing the UUID
		.unwrap_or("")
		.split(' ')
		.nth(1)
		{
		None => panic!("No network interface found"),
		Some(id) => {
            println!("The MAC address is {}", id);
			// return id.to_string();
		}
	}    
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants