change MAC retrieval to use ifconfig ('ip' would be an additional dependency)

This commit is contained in:
lars 2007-09-15 16:41:41 +00:00
parent a695d37b8c
commit 524555c8e8
1 changed files with 14 additions and 8 deletions

View File

@ -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: