Exemple #1
0
 def mode(self, mode=None):
     if not mode:
         return self.param('mode')
     try:
         ifconfig(self.dev, 'down')
         iwconfig(self.dev, 'mode', mode)
         ifconfig(self.dev, 'up')
         return self.mode() == mode
     except:
         return False
Exemple #2
0
 def mode(self, mode=None):
     if not mode:
         return self.param("mode")
     try:
         ifconfig(self.dev, "down")
         iwconfig(self.dev, "mode", mode)
         ifconfig(self.dev, "up")
         return self.mode() == mode
     except:
         return False
Exemple #3
0
def set_channel(ifaces, channels):
    """Sets the monitor mode (or remove it) from an interface.
        PLEASE RESTART L2socket TO ENABLE THIS CHANGE!
        PLEASE RESTART L2socket TO ENABLE THIS CHANGE!
        PLEASE RESTART L2socket TO ENABLE THIS CHANGE!
        params:
         - iface: the iwconfig interface
         - channel: the iface channel
        """
    assert len(ifaces) == len(channels)
    for iface, channel in zip(ifaces, channels):
        sh.iwconfig(iface, "channel", channel)
Exemple #4
0
    def connect(self, essid, key):
        try:
            from sh import dhcpcd as dhcp
        except CommandNotFound:
            from sh import dhclient as dhcp
        if self._dhcpcd_pid is not None:
            kill(self._dhcpcd_pid)

        iwconfig(self.dev, 'essid', essid)
        iwconfig(self.dev, 'key', key)
        for line in dhcp(self.dev, _err_to_out, _iter=True):
            m = ManagedInterface._DHCPCD_SUCCESS_LINE.match(line)
            if m is not None:
                self._dhcpcd_pid = m.group(1)
                return True
        return False
Exemple #5
0
    def connect(self, essid, key):
        try:
            from sh import dhcpcd as dhcp
        except CommandNotFound:
            from sh import dhclient as dhcp
        if self._dhcpcd_pid is not None:
            kill(self._dhcpcd_pid)

        iwconfig(self.dev, 'essid', essid)
        iwconfig(self.dev, 'key', key)
        for line in dhcp(self.dev, _err_to_out, _iter=True):
            m = ManagedInterface._DHCPCD_SUCCESS_LINE.match(line)
            if m is not None:
                self._dhcpcd_pid = m.group(1)
                return True
        return False
Exemple #6
0
 def param(self, param):
     params = [
         p.split(':', 1) for p in iwconfig(self.dev).split('  ') if ':' in p
     ]
     for a, b in params:
         if a.lower() == param:
             return b
     raise KeyError
Exemple #7
0
 def _available_ifs(self):
     for i in iwconfig().split('\n\n'):
         if 'IEEE 802' in i:
             dev = i.split('IEEE 802', 1)[0].strip()
             if (
                 (not self._to_use_if or dev in self._to_use_if)
                 and dev not in self._used_if
                 and dev != settings.DUMMY_MANAGED_IF
             ):
                 self._used_if.append(dev)
                 yield dev
Exemple #8
0
 def get_linerate_wireless(self,interface):
     try:
         iwres = iwconfig(interface,_ok_code=[0,1])
         rx = re.compile("Bit Rate=([0-9]+)\s*Mb/s", re.MULTILINE | re.IGNORECASE)
         lrg = rx.search(iwres)
         if lrg.groups() != ():
             bit_rate = int(lrg.group(1)) # Mbits/s
             lr = (InterfaceType.Wireless,bit_rate * 1000 * 1000 / 8) # convert Mbit/s to bytes/s (NOTE: 1000, not 1024; see IEEE 802.3-2008)
             return lr
         else:
             return None,None
     except ErrorReturnCode:
         return None,None
Exemple #9
0
 def param(self, param):
     params = [p.split(":", 1) for p in iwconfig(self.dev).split("  ") if ":" in p]
     for a, b in params:
         if a.lower() == param:
             return b
     raise KeyError