diff --git a/plugins/network/network.py b/plugins/network/network.py index 4a8fb96..d2c5204 100644 --- a/plugins/network/network.py +++ b/plugins/network/network.py @@ -29,6 +29,7 @@ __revision__ = "$Id$" import subprocess import os +import re import cryptobox.plugins.base @@ -239,7 +240,6 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): TODO: do not use "address_type" for ip and netmask, but return both in two tuples """ - import re ## get the current IP of the network interface proc = subprocess.Popen( shell = False, @@ -374,24 +374,30 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin): else: return DEFAULT_INTERFACE + def __get_interface_mac(self, interface="None"): """Return the MAC address of the given network interface """ - import re, string + invalid_mac = "00:00:00:00:00:00" proc = subprocess.Popen( stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = False, - args = ["ip", "link", "show", interface] ) + args = [self.root_action.IFCONFIG_BIN, interface] ) proc.wait() if proc.returncode != 0: - self.cbox.log.warn("[network] error from ip command: %s" % str(proc.stderr.read())) + self.cbox.log.warn("[network] error from ifconfig command: %s" % str(proc.stderr.read())) self.cbox.log.warn("[network] failed to determine MAC address on: %s" % interface) + return invalid_mac output = str(proc.stdout.read()) - regex = re.compile('[0-9a-f][0-9a-f]:+') - mac = regex.findall(output) - mac = string.join(mac[:5], "") - return mac + ## the MAC is the only string made up of six hexadecimal bytes + regex = re.compile('((?:[0-9A-F]{2}:){5}[0-9A-F]{2})') + match = regex.search(output) + if match: + return match.group() + else: + return invalid_mac + def __IP_is_valid(self, ip1, ip2, ip3, ip4): try: