예제 #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'))
예제 #2
0
파일: networking.py 프로젝트: winguru/wicd
    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 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(cmp=comp, reverse=True)

        return aps