change MAC retrieval to use ifconfig ('ip' would be an additional dependency)
This commit is contained in:
parent
a695d37b8c
commit
524555c8e8
|
@ -29,6 +29,7 @@ __revision__ = "$Id$"
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import cryptobox.plugins.base
|
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
|
TODO: do not use "address_type" for ip and netmask, but return both in
|
||||||
two tuples
|
two tuples
|
||||||
"""
|
"""
|
||||||
import re
|
|
||||||
## get the current IP of the network interface
|
## get the current IP of the network interface
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
shell = False,
|
shell = False,
|
||||||
|
@ -374,24 +374,30 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
|
||||||
else:
|
else:
|
||||||
return DEFAULT_INTERFACE
|
return DEFAULT_INTERFACE
|
||||||
|
|
||||||
|
|
||||||
def __get_interface_mac(self, interface="None"):
|
def __get_interface_mac(self, interface="None"):
|
||||||
"""Return the MAC address of the given network interface
|
"""Return the MAC address of the given network interface
|
||||||
"""
|
"""
|
||||||
import re, string
|
invalid_mac = "00:00:00:00:00:00"
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
stderr = subprocess.PIPE,
|
stderr = subprocess.PIPE,
|
||||||
shell = False,
|
shell = False,
|
||||||
args = ["ip", "link", "show", interface] )
|
args = [self.root_action.IFCONFIG_BIN, interface] )
|
||||||
proc.wait()
|
proc.wait()
|
||||||
if proc.returncode != 0:
|
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)
|
self.cbox.log.warn("[network] failed to determine MAC address on: %s" % interface)
|
||||||
|
return invalid_mac
|
||||||
output = str(proc.stdout.read())
|
output = str(proc.stdout.read())
|
||||||
regex = re.compile('[0-9a-f][0-9a-f]:+')
|
## the MAC is the only string made up of six hexadecimal bytes
|
||||||
mac = regex.findall(output)
|
regex = re.compile('((?:[0-9A-F]{2}:){5}[0-9A-F]{2})')
|
||||||
mac = string.join(mac[:5], "")
|
match = regex.search(output)
|
||||||
return mac
|
if match:
|
||||||
|
return match.group()
|
||||||
|
else:
|
||||||
|
return invalid_mac
|
||||||
|
|
||||||
|
|
||||||
def __IP_is_valid(self, ip1, ip2, ip3, ip4):
|
def __IP_is_valid(self, ip1, ip2, ip3, ip4):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue