Browse Source

* network plugin displays mac address

master
age 15 years ago
parent
commit
247b188aec
  1. 5
      plugins/network/form_network.cs
  2. 1
      plugins/network/language.hdf
  3. 20
      plugins/network/network.py

5
plugins/network/form_network.cs

@ -89,6 +89,11 @@
</legend>
<?cs call:print_form_header("network_address", "network") ?>
<?cs call:show_help(Lang.Plugins.network.Help.DHCP) ?>
<p>
<?cs var:html_escape(Lang.Plugins.network.Text.Interface) ?>:
<?cs var:html_escape(Data.Plugins.network.mac) ?>
(<?cs var:html_escape(Data.Plugins.network.interface) ?>)
</p>
<p>
<input type="checkbox" name="confirm_dhcp" value="1" id="confirm_dhcp"
<?cs if:Data.Plugins.network.dhcp == "use" ?>checked<?cs /if ?>

1
plugins/network/language.hdf

@ -13,6 +13,7 @@ Text {
NM = Netmask
GW = Gateway
DHCP = Configure the network interface automatically (Caution, please read help!)
Interface = Network device
}
Button {

20
plugins/network/network.py

@ -229,6 +229,8 @@ class network(cryptobox.plugins.base.CryptoBoxPlugin):
self.hdf[self.hdf_prefix + "gw.oc4"] = oc4
if self.prefs.has_key("_dhcp"):
self.hdf[self.hdf_prefix + "dhcp"] = str(self.prefs["_dhcp"])
self.hdf[self.hdf_prefix + "interface"] = str(self.__get_interface())
self.hdf[self.hdf_prefix + "mac"] = str(self.__get_interface_mac(self.__get_interface()))
def __get_current_ip(self, address_type="ip"):
@ -372,6 +374,24 @@ 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
proc = subprocess.Popen(
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = False,
args = ["ip", "link", "show", 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] failed to determine MAC address on: %s" % interface)
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
def __IP_is_valid(self, ip1, ip2, ip3, ip4):
try:

Loading…
Cancel
Save