I am using console commands in python, however, it is not outputting the value I want.
The path is:
#ifconfig -a | grep "HWaddr"
eth0 Link encap:Ethernet HWaddr 30:0E:D5:C7:1A:EF
eth1 Link encap:Ethernet HWaddr 30:0E:D5:C7:1A:F0
mac=subprocess.check_output('ifconfig -a | grep "HWaddr"')
print "%s" %(mac)
import subprocess def getmac(command): return subprocess.check_output(command, shell=True) command = "ifconfig -a | grep HWaddr" print "%s" %(getmac(command).split()) # or print out the entire list to see which index your HWAddr corresponds to # print "%s" %(getmac(command).split())
shell=True isn't recommended as per Python docs
You could have also returned
However, in the above case, you might get an
OSError or a
CalledProcessError(retcode, cmd, output=output) depending on whether you passed your commands as a list, which can be solved if you explicitly mention your python path as per this