From 914fe7e7502eca5464448d37c194f9841acdb9a6 Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 27 May 2016 23:00:05 -0600 Subject: [PATCH] Randomize the 4th and 5th bytes when provided with a base mac address. Fixes #522. --- gns3server/modules/qemu/qemu_vm.py | 5 +++-- gns3server/utils/__init__.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index d0305ccc..2006a285 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -28,6 +28,7 @@ import subprocess import shlex import asyncio import socket +import random import gns3server from gns3server.utils import parse_version @@ -493,9 +494,9 @@ class QemuVM(BaseVM): """ if not mac_address: - self._mac_address = "00:00:ab:%s:%s:00" % (self.id[-4:-2], self.id[-2:]) + self._mac_address = "12:34:%02x:%02x:%02x:00" % (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) else: - self._mac_address = mac_address + self._mac_address = mac_address[:8] + ":%02x:%02x:00" % (random.randint(0, 255), random.randint(0, 255)) log.info('QEMU VM "{name}" [{id}]: MAC address changed to {mac_addr}'.format(name=self._name, id=self._id, diff --git a/gns3server/utils/__init__.py b/gns3server/utils/__init__.py index 9f8ea4a7..06b56d0d 100644 --- a/gns3server/utils/__init__.py +++ b/gns3server/utils/__init__.py @@ -30,19 +30,20 @@ def force_unix_path(path): return posixpath.normpath(path) -def macaddress_to_int(macaddress): +def macaddress_to_int(mac_address): """ Convert a macaddress with the format 00:0c:29:11:b0:0a to a int - :param macaddress: The mac address + :param mac_address: The mac address + :returns: Integer """ - return int(macaddress.replace(":", ""), 16) + return int(mac_address.replace(":", ""), 16) def int_to_macaddress(integer): """ - Convert an integer to a macaddress + Convert an integer to a mac address """ return ":".join(textwrap.wrap("%012x" % (integer), width=2))