getmac

#!/usr/bin/env python
 
####################################################
# #
# Copyright (C) 2016 Ringfree Communications LLC #
# By Kendall Weaver <kendall@ringfree.com> #
# #
####################################################
 
import os, sys, subprocess
 
try:
sys.argv[1]

except:
print("Usage: getmac [EXTENSION]\n")
sys.exit(0)
 
CWD = os.getcwd()
 
command = "ls {0}*".format(sys.argv[1])
pipe = subprocess.Popen(command, shell=True, cwd=CWD, stdout=subprocess.PIPE).stdout
data = pipe.read()
 
if data == '':
sys.exit(1)
else:
arr = data.split('\n')
 
for item in arr:
try:
withcfg = item.split(sys.argv[1])
last = withcfg[1].split('.')
 
if len(last[0]) == 6:
command = "grep -l {0} *.cfg".format(item)
pipe = subprocess.Popen(command, shell=True, cwd=CWD, stdout=subprocess.PIPE).stdout
data = pipe.read()
maccfg = data.replace('\n', '')
 
if maccfg != '':
os.system("ls -la {0}".format(maccfg))
 
except:
continue