Ejemplo n.º 1
0
    def test_find_mac(self):
        data = '''\

fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
'''
        def mock_popen(cmd):
            return io.BytesIO(data)

        path = os.environ.get("PATH", os.defpath).split(os.pathsep)
        path.extend(('/sbin', '/usr/sbin'))
        for dir in path:
            executable = os.path.join(dir, 'ifconfig')
            if (os.path.exists(executable) and
                os.access(executable, os.F_OK | os.X_OK) and
                not os.path.isdir(executable)):
                break
        else:
            self.skipTest('requires ifconfig')

        with test_support.swap_attr(os, 'popen', mock_popen):
            mac = uuid._find_mac(
                command='ifconfig',
                args='',
                hw_identifiers=['hwaddr'],
                get_index=lambda x: x + 1,
            )
            self.assertEqual(mac, 0x1234567890ab)
Ejemplo n.º 2
0
    def test_find_mac(self):
        data = '''\

fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
'''

        def mock_popen(cmd):
            return io.BytesIO(data)

        path = os.environ.get("PATH", os.defpath).split(os.pathsep)
        path.extend(('/sbin', '/usr/sbin'))
        for dir in path:
            executable = os.path.join(dir, 'ifconfig')
            if (os.path.exists(executable)
                    and os.access(executable, os.F_OK | os.X_OK)
                    and not os.path.isdir(executable)):
                break
        else:
            self.skipTest('requires ifconfig')

        with test_support.swap_attr(os, 'popen', mock_popen):
            mac = uuid._find_mac(
                command='ifconfig',
                args='',
                hw_identifiers=['hwaddr'],
                get_index=lambda x: x + 1,
            )
            self.assertEqual(mac, 0x1234567890ab)
Ejemplo n.º 3
0
def _uuid_lanscan_iface(iface):
    # type: (str) -> Optional[str]
    from uuid import _find_mac  # type: ignore
    if not PY2:
        iface = bytes(iface, 'utf-8')  # type: ignore
    mac = _find_mac('lanscan', '-ai', [iface], lambda i: 0)
    if mac:
        return _uuid_convert(mac)
    return None
Ejemplo n.º 4
0
    def test_find_mac(self):
        data = """
fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
"""
        popen = unittest.mock.MagicMock()
        popen.stdout = io.BytesIO(data.encode())
        with unittest.mock.patch.object(shutil, 'which', return_value=
            '/sbin/ifconfig'):
            with unittest.mock.patch.object(subprocess, 'Popen',
                return_value=popen):
                mac = uuid._find_mac(command='ifconfig', args='',
                    hw_identifiers=[b'hwaddr'], get_index=lambda x: x + 1)
        self.assertEqual(mac, 20015998341291)
Ejemplo n.º 5
0
    def test_find_mac(self):
        data = '''\

fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
'''
        def mock_popen(cmd):
            return io.StringIO(data)

        with support.swap_attr(os, 'popen', mock_popen):
            mac = uuid._find_mac(
                command='ifconfig',
                args='',
                hw_identifiers=['hwaddr'],
                get_index=lambda x: x + 1,
            )
            self.assertEqual(mac, 0x1234567890ab)
Ejemplo n.º 6
0
    def __set_identity(self):
        node = None
        if sys.platform == 'win32':
            for getter in [uuid._netbios_getnode, uuid._ipconfig_getnode]:
                node = getter()
                if node:
                    break
        else:
            # Linux only, find mac address using ifconfig command. taken from uuid._ifconfig_getnode
            for args in ('eth0', 'wlan0', 'en0'):  # TODO: other possible network interface name
                node = uuid._find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i + 1)
                if node:
                    break

        if node is None:
            raise RuntimeError("No network interface found.")
        self.__mac_address = ':'.join([str('%012x' % node)[x:x + 2] for x in range(0, 12, 2)])
        url = 'xiboside://%s/%s/%s' % (sys.platform, os.name, self.__mac_address)
        self.__keys['hardware'] = uuid.uuid3(uuid.NAMESPACE_URL, url)
Ejemplo n.º 7
0
    def test_find_mac(self):
        data = '''\

fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
'''

        def mock_popen(cmd):
            return io.StringIO(data)

        with support.swap_attr(os, 'popen', mock_popen):
            mac = uuid._find_mac(
                command='ifconfig',
                args='',
                hw_identifiers=['hwaddr'],
                get_index=lambda x: x + 1,
            )
            self.assertEqual(mac, 0x1234567890ab)
Ejemplo n.º 8
0
    def test_find_mac(self):
        data = '''
fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
'''

        popen = unittest.mock.MagicMock()
        popen.stdout = io.BytesIO(data.encode())

        with unittest.mock.patch.object(shutil, 'which',
                                        return_value='/sbin/ifconfig'):
            with unittest.mock.patch.object(subprocess, 'Popen',
                                            return_value=popen):
                mac = uuid._find_mac(
                    command='ifconfig',
                    args='',
                    hw_identifiers=[b'hwaddr'],
                    get_index=lambda x: x + 1,
                )

        self.assertEqual(mac, 0x1234567890ab)
Ejemplo n.º 9
0
    def test_find_mac(self):
        data = '''\

fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
'''
        def mock_popen(cmd):
            return io.StringIO(data)

        if shutil.which('ifconfig') is None:
            path = os.pathsep.join(('/sbin', '/usr/sbin'))
            if shutil.which('ifconfig', path=path) is None:
                self.skipTest('requires ifconfig')

        with support.swap_attr(os, 'popen', mock_popen):
            mac = uuid._find_mac(
                command='ifconfig',
                args='',
                hw_identifiers=['hwaddr'],
                get_index=lambda x: x + 1,
            )
            self.assertEqual(mac, 0x1234567890ab)
Ejemplo n.º 10
0
    def test_find_mac(self):
        data = '''\

fake hwaddr
cscotun0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:ab
'''
        def mock_popen(cmd):
            return io.StringIO(data)

        if shutil.which('ifconfig') is None:
            path = os.pathsep.join(('/sbin', '/usr/sbin'))
            if shutil.which('ifconfig', path=path) is None:
                self.skipTest('requires ifconfig')

        with support.swap_attr(os, 'popen', mock_popen):
            mac = uuid._find_mac(
                command='ifconfig',
                args='',
                hw_identifiers=['hwaddr'],
                get_index=lambda x: x + 1,
            )
            self.assertEqual(mac, 0x1234567890ab)
Ejemplo n.º 11
0
    def __set_identity(self):
        node = None
        if sys.platform == 'win32':
            for getter in [uuid._netbios_getnode, uuid._ipconfig_getnode]:
                node = getter()
                if node:
                    break
        else:
            # Linux only, find mac address using ifconfig command. taken from uuid._ifconfig_getnode
            for args in ('eth0', 'wlan0',
                         'en0'):  # TODO: other possible network interface name
                node = uuid._find_mac('ifconfig', args, ['hwaddr', 'ether'],
                                      lambda i: i + 1)
                if node:
                    break

        if node is None:
            raise RuntimeError("No network interface found.")
        self.__mac_address = ':'.join(
            [str('%012x' % node)[x:x + 2] for x in range(0, 12, 2)])
        url = 'xiboside://%s/%s/%s' % (sys.platform, os.name,
                                       self.__mac_address)
        self.__keys['hardware'] = uuid.uuid3(uuid.NAMESPACE_URL, url)