Exemplo n.º 1
0
    def set_dns_addresses(self, iface):
        """ Set the DNS address(es).

        If static DNS servers or global DNS servers are specified, set them.
        Otherwise do nothing.
        
        """
        if self.network.get('use_global_dns'):
            iface.SetDNS(misc.Noneify(self.global_dns_1),
                         misc.Noneify(self.global_dns_2),
                         misc.Noneify(self.global_dns_3),
                         misc.Noneify(self.global_dns_dom),
                         misc.Noneify(self.global_search_dom))
        elif self.network.get('use_static_dns') and (
                self.network.get('dns1') or self.network.get('dns2')
                or self.network.get('dns3')):
            self.SetStatus('setting_static_dns')
            iface.SetDNS(self.network.get('dns1'), self.network.get('dns2'),
                         self.network.get('dns3'),
                         self.network.get('dns_domain'),
                         self.network.get('search_domain'))
Exemplo n.º 2
0
    def Scan(self, essid=None):
        """Scan for available wireless networks.

        Keyword arguments:
        essid -- The essid of a hidden network

        Returns:
        A list of available networks sorted by strength.

        """
        def comp(x, y):
            """Custom sorting function."""
            if 'quality' in x:
                key = 'quality'
            else:
                key = 'strength'

            return ((x[key] > y[key]) -
                    (x[key] < y[key]))  # cmp(x[key], y[key])

        if not self.wiface:
            return []
        wiface = self.wiface

        # Prepare the interface for scanning
        wiface.Up()

        # If there is a hidden essid then set it now, so that when it is
        # scanned it will be recognized.
        # Note: this does not always work, sometimes we have to pass it with
        # "iwlist wlan0 scan essid -- XXXXX"
        essid = misc.Noneify(essid)
        if essid is not None:
            print(('Setting hidden essid ' + essid))
            wiface.SetEssid(essid)
            # sleep for a bit; scanning to fast will result in nothing
            time.sleep(1)

        aps = wiface.GetNetworks(essid)
        aps.sort(key=cmp_to_key(comp), reverse=True)

        return aps
Exemplo n.º 3
0
    def Scan(self, essid=None):
        """ Scan for available wireless networks.

        Keyword arguments:
        essid -- The essid of a hidden network

        Returns:
        A list of available networks sorted by strength.

        """
        def get_key_value(x):
            """ Custom sorting function. """
            if 'quality' in x:
                key = 'quality'
            else:
                key = 'strength'
            return x[key]

        if not self.wiface:
            return []
        wiface = self.wiface

        # Prepare the interface for scanning
        wiface.Up()

        # If there is a hidden essid then set it now, so that when it is
        # scanned it will be recognized.
        essid = misc.Noneify(essid)
        if essid is not None:
            print('Setting hidden essid' + essid)
            wiface.SetEssid(essid)
            # sleep for a bit; scanning to fast will result in nothing
            time.sleep(1)

        aps = wiface.GetNetworks()
        aps = sorted(aps, key=get_key_value, reverse=True)

        return aps
Exemplo n.º 4
0
 def test_noneify_8(self):
     self.assertTrue(misc.Noneify('1'))
Exemplo n.º 5
0
 def test_noneify_7(self):
     self.assertTrue(misc.Noneify('True'))
Exemplo n.º 6
0
 def test_noneify_6(self):
     self.assertFalse(misc.Noneify(False))
Exemplo n.º 7
0
 def test_noneify_5(self):
     self.assertFalse(misc.Noneify('0'))
Exemplo n.º 8
0
 def test_noneify_4(self):
     self.assertFalse(misc.Noneify('False'))
Exemplo n.º 9
0
 def test_noneify_3(self):
     self.assertEqual(misc.Noneify(None), None)
Exemplo n.º 10
0
 def test_noneify_2(self):
     self.assertEqual(misc.Noneify(''), None)
Exemplo n.º 11
0
 def test_noneify_13(self):
     self.assertEqual(misc.Noneify(0, False), 0)
Exemplo n.º 12
0
 def test_noneify_12(self):
     self.assertEqual(misc.Noneify(1, False), 1)
Exemplo n.º 13
0
 def test_noneify_11(self):
     self.assertEqual(misc.Noneify(5), 5)
Exemplo n.º 14
0
 def test_noneify_10(self):
     self.assertEqual(misc.Noneify('randomtext'), 'randomtext')
Exemplo n.º 15
0
 def test_noneify_9(self):
     self.assertTrue(misc.Noneify(True))
Exemplo n.º 16
0
 def test_noneify_1(self):
     self.assertEquals(misc.Noneify('None'), None)