Fix detect utils without path. Fix using ifconfig.

develop
Mike Hiretsky 12 years ago
parent cd60886fd8
commit 0ac464c846

@ -934,7 +934,7 @@ def getProgPath(progname):
env = {"LANG":"C"} env = {"LANG":"C"}
env.update(os.environ.items() + [("PATH",getpathenv())] +\ env.update(os.environ.items() + [("PATH",getpathenv())] +\
env.items()) env.items())
res = runOsCommand("which %s"%progname,env_dict=env) res = runOsCommand("which %s"%baseprogname,env_dict=env)
if res[0] == 0: if res[0] == 0:
return res[1][0].strip() return res[1][0].strip()
elif path.isabs(progname) and path.exists(progname): elif path.isabs(progname) and path.exists(progname):

@ -84,8 +84,10 @@ def checkMask(mask):
def getIpAndMask(interface="eth0"): def getIpAndMask(interface="eth0"):
"""Get ip and mask from interface""" """Get ip and mask from interface"""
ifconfig = process('/sbin/ifconfig',interface) ipconfigProg = checkUtils('/sbin/ifconfig')
res = re.search(r"inet addr:(\S+)\s.*Mask:(\S+)",ifconfig.read(),re.S) ifconfig = process(ipconfigProg,interface)
res = re.search(r"inet(?: addr:| )(\S+)\s.*(?:Mask:|netmask )(\S+)",
ifconfig.read(),re.S)
if res: if res:
return res.groups() return res.groups()
else: else:
@ -139,7 +141,7 @@ def receiveMac(interface="eth0"):
"""Get MAC from interface""" """Get MAC from interface"""
ipconfigProg = checkUtils('/sbin/ifconfig') ipconfigProg = checkUtils('/sbin/ifconfig')
ifconfig = process(ipconfigProg,interface) ifconfig = process(ipconfigProg,interface)
res = re.search(r"HWaddr\s(\S+)",ifconfig.read(),re.S) res = re.search(r"(?:HWaddr|ether)\s(\S+)",ifconfig.read(),re.S)
if res: if res:
return res.group(1) return res.group(1)
else: else:
@ -149,7 +151,8 @@ def receiveIpAndMask(interface="eth0"):
"""Get ip and mask from interface""" """Get ip and mask from interface"""
ipconfigProg = checkUtils('/sbin/ifconfig') ipconfigProg = checkUtils('/sbin/ifconfig')
ifconfig = process(ipconfigProg,interface) ifconfig = process(ipconfigProg,interface)
res = re.search(r"inet addr:(\S+)\s.*Mask:(\S+)",ifconfig.read(),re.S) res = re.search(r"inet(?: addr:| )(\S+)\s.*(?:Mask:|netmask )(\S+)",
ifconfig.read(),re.S)
if res: if res:
return res.groups() return res.groups()
else: else:

Loading…
Cancel
Save