Exemplo n.º 1
0
Arquivo: pifi.py Projeto: ihelal/pifi
def status(nm=nm):
    devices = 0

    for ApModeDevice in nm.managedAPCapableDevices():
        devices += 1
        print("Network Mangager reports AP mode support on %s" %
              ApModeDevice.Interface)
        if ApModeDevice.State != 100:
            print("Device is not activated")
            exit(0)
        current_connection = ApModeDevice.GetAppliedConnection(0)
        if 'mode' in current_connection[0][
                '802-11-wireless'] and current_connection[0][
                    '802-11-wireless']['mode'] == "ap":
            print("Device is currently acting as an Access Point")
        else:
            ssid = current_connection[0]['802-11-wireless']['ssid']
            ssid = bytearray([ord(byte) for byte in ssid])
            print("Device is connected to %s" % ssid.decode("utf-8"))

    if (devices == 0):
        print(
            "ERROR: Network Manager reports no AP mode support on any managed device"
        )
        exit(2)
Exemplo n.º 2
0
    def test_managed_ap_devices_multiple_ap_devices(self):
        wi_dev = mock.MagicMock()
        wi_dev.configure_mock(**{'WirelessCapabilities': 100})

        dev = mock.MagicMock()
        dev.configure_mock(**{
            'DeviceType': 2,
            'SpecificDevice.return_value': wi_dev
        })

        non_wifi_dev = mock.MagicMock()
        non_wifi_dev.configure_mock(**{'DeviceType': 0})

        nm = mock.MagicMock()
        nm.configure_mock(
            **{
                'NetworkManager.GetDevices.return_value':
                [dev, non_wifi_dev, dev],
                'NM_DEVICE_TYPE_WIFI': 2,
                'NM_WIFI_DEVICE_CAP_AP': 100
            })

        generator = nm_helper.managedAPCapableDevices(NetworkManager=nm)

        self.assertEqual(dev, next(generator))
        self.assertEqual(dev, next(generator))

        with self.assertRaises(StopIteration):
            next(generator)