Determine Active Nic Address Using Python Console Commands
I am trying to find an active NIC, an active NIC is one where the command wil return UP for me. In my command: # cat /sys/class/net/eth0/operstate I am returned a value of UP In a
Solution 1:
x is a variable containing the value: 1 or 2 or 3 or 4. The code-snippet you've treats x as a string. Also, the code-snippet tries to enclose single quotes within single quotes generating the error.
Modify as below and it should work.
Also, there's a syntax error in the above code - you're missing a colon after the 'if' clause.
mylist= [0,1,2,3]
for x in mylist:
withopen('/sys/class/net/{}/operstate'.format(x)) as f:
mac_eth0= f.read().rstrip()
if mac_eth0 == "up":
print"it is %s" %(mac_eth0)
Post a Comment for "Determine Active Nic Address Using Python Console Commands"