Sumit Naiksatam fad053533c Changed the directory structure to a more organized one.
Fixed the imports to reflect the new structure.
2011-07-31 11:38:26 -07:00

38 lines
1.3 KiB
Python

import sys
import subprocess
def get_next_dynic(argv=[]):
cmd = ["ifconfig", "-a"]
f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\
communicate()[0]
eths = [lines.split(' ')[0] for lines in f_cmd_output.splitlines() \
if "eth" in lines]
#print eths
for eth in eths:
cmd = ["ethtool", "-i", eth]
f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\
communicate()[0]
bdf = [lines.split(' ')[1] for lines in f_cmd_output.splitlines() \
if "bus-info" in lines]
#print bdf
cmd = ["lspci", "-n", "-s", bdf[0]]
f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\
communicate()[0]
deviceid = [(lines.split(':')[3]).split(' ')[0] \
for lines in f_cmd_output.splitlines()]
#print deviceid
if deviceid[0] == "0044":
cmd = ["/usr/sbin/ip", "link", "show", eth]
f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\
communicate()[0]
used = [lines for lines in f_cmd_output.splitlines() \
if "UP" in lines]
if not used:
break
return eth
if __name__ == '__main__':
nic = get_next_dynic(sys.argv)
print nic