I'm trying to use grep to get me en0's mac address. What I'm trying to do is store that in a variable called original_mac.
This does not seem to be working though. When I type ifconfig en0 | grep ether
ifconfig en0 | grep ether
i get ether: <mac_address>
. I just want to get the mac address part of it.
#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'. So this should work:
original_mac = subprocess.check_output("ifconfig en0 | grep ether | awk {print $2}", shell=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.