简体   繁体   English

仅从ifconfig获取MAC地址

[英]Getting MAC address only from ifconfig

I'm trying to use grep to get me en0's mac address. 我正在尝试使用grep获取我en0的mac地址。 What I'm trying to do is store that in a variable called original_mac. 我想做的是将其存储在一个名为original_mac的变量中。

This does not seem to be working though. 不过,这似乎不起作用。 When I type ifconfig en0 | grep ether 当我键入ifconfig en0 | grep ether ifconfig en0 | grep ether i get ether: <mac_address> . ifconfig en0 | grep ether我得到ether: <mac_address> I just want to get the mac address part of it. 我只想获取其中的mac地址部分。

#get original mac address
    global original_mac
    original_mac = subprocess.check_output("ifconfig en0 | grep ether | awk {print $2}")
    print "mac: "+original_mac

You have to either pass a list to check_output or use 'shell=True'. 您必须将列表传递给check_output或使用'shell = True'。 So this should work: 所以这应该工作:

original_mac = subprocess.check_output("ifconfig en0 | grep ether | awk {print $2}", shell=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM