mirror of
https://github.com/gryf/wicd.git
synced 2026-03-06 17:35:48 +01:00
Added a neediface decorator to replace using "if not self.iface return..." in every method that needs it.
This commit is contained in:
@@ -34,7 +34,7 @@ from wicd import misc
|
|||||||
from wicd import wnettools
|
from wicd import wnettools
|
||||||
from wicd import wpath
|
from wicd import wpath
|
||||||
from wicd.wnettools import *
|
from wicd.wnettools import *
|
||||||
from wicd.wnettools import wep_pattern, signaldbm_pattern
|
from wicd.wnettools import wep_pattern, signaldbm_pattern, neediface
|
||||||
|
|
||||||
import iwscan
|
import iwscan
|
||||||
import wpactrl
|
import wpactrl
|
||||||
@@ -124,6 +124,7 @@ class Interface(wnettools.BaseInterface):
|
|||||||
# We don't need any external apps so just return
|
# We don't need any external apps so just return
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetIP(self, ifconfig=""):
|
def GetIP(self, ifconfig=""):
|
||||||
""" Get the IP address of the interface.
|
""" Get the IP address of the interface.
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ class Interface(wnettools.BaseInterface):
|
|||||||
|
|
||||||
return socket.inet_ntoa(raw_ip[20:24])
|
return socket.inet_ntoa(raw_ip[20:24])
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def IsUp(self):
|
def IsUp(self):
|
||||||
""" Determines if the interface is up.
|
""" Determines if the interface is up.
|
||||||
|
|
||||||
@@ -148,7 +150,6 @@ class Interface(wnettools.BaseInterface):
|
|||||||
True if the interface is up, False otherwise.
|
True if the interface is up, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
data = (self.iface + '\0' * 16)[:18]
|
data = (self.iface + '\0' * 16)[:18]
|
||||||
try:
|
try:
|
||||||
result = fcntl.ioctl(self.sock.fileno(), SIOCGIFFLAGS, data)
|
result = fcntl.ioctl(self.sock.fileno(), SIOCGIFFLAGS, data)
|
||||||
@@ -174,6 +175,7 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
|
|||||||
wnettools.BaseWiredInterface.__init__(self, iface, verbose)
|
wnettools.BaseWiredInterface.__init__(self, iface, verbose)
|
||||||
Interface.__init__(self, iface, verbose)
|
Interface.__init__(self, iface, verbose)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def GetPluggedIn(self):
|
def GetPluggedIn(self):
|
||||||
""" Get the current physical connection state.
|
""" Get the current physical connection state.
|
||||||
|
|
||||||
@@ -185,7 +187,6 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
|
|||||||
True if a link is detected, False otherwise.
|
True if a link is detected, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
if self.ethtool_cmd and self.link_detect in [misc.ETHTOOL, misc.AUTO]:
|
if self.ethtool_cmd and self.link_detect in [misc.ETHTOOL, misc.AUTO]:
|
||||||
return self._eth_get_plugged_in()
|
return self._eth_get_plugged_in()
|
||||||
elif self.miitool_cmd and self.link_detect in [misc.MIITOOL, misc.AUTO]:
|
elif self.miitool_cmd and self.link_detect in [misc.MIITOOL, misc.AUTO]:
|
||||||
@@ -254,6 +255,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
Interface.__init__(self, iface, verbose)
|
Interface.__init__(self, iface, verbose)
|
||||||
self.scan_iface = None
|
self.scan_iface = None
|
||||||
|
|
||||||
|
@neediface([])
|
||||||
def GetNetworks(self):
|
def GetNetworks(self):
|
||||||
""" Get a list of available wireless networks.
|
""" Get a list of available wireless networks.
|
||||||
|
|
||||||
@@ -405,6 +407,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
print 'wpa_supplicant authentication may have failed.'
|
print 'wpa_supplicant authentication may have failed.'
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def StopWPA(self):
|
def StopWPA(self):
|
||||||
""" Terminates wpa_supplicant using its ctrl interface. """
|
""" Terminates wpa_supplicant using its ctrl interface. """
|
||||||
wpa = self._connect_to_wpa_ctrl_iface()
|
wpa = self._connect_to_wpa_ctrl_iface()
|
||||||
@@ -469,9 +472,9 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetBSSID(self, iwconfig=None):
|
def GetBSSID(self, iwconfig=None):
|
||||||
""" Get the MAC address for the interface. """
|
""" Get the MAC address for the interface. """
|
||||||
if not self.iface: return ""
|
|
||||||
data = (self.iface + '\0' * 32)[:32]
|
data = (self.iface + '\0' * 32)[:32]
|
||||||
try:
|
try:
|
||||||
result = fcntl.ioctl(self.sock.fileno(), SIOCGIWAP, data)[16:]
|
result = fcntl.ioctl(self.sock.fileno(), SIOCGIWAP, data)[16:]
|
||||||
@@ -482,9 +485,9 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
raw_addr = struct.unpack("xxBBBBBB", result[:8])
|
raw_addr = struct.unpack("xxBBBBBB", result[:8])
|
||||||
return "%02X:%02X:%02X:%02X:%02X:%02X" % raw_addr
|
return "%02X:%02X:%02X:%02X:%02X:%02X" % raw_addr
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetCurrentBitrate(self, iwconfig=None):
|
def GetCurrentBitrate(self, iwconfig=None):
|
||||||
""" Get the current bitrate for the interface. """
|
""" Get the current bitrate for the interface. """
|
||||||
if not self.iface: return ""
|
|
||||||
data = (self.iface + '\0' * 32)[:32]
|
data = (self.iface + '\0' * 32)[:32]
|
||||||
fmt = "ihbb"
|
fmt = "ihbb"
|
||||||
size = struct.calcsize(fmt)
|
size = struct.calcsize(fmt)
|
||||||
@@ -507,6 +510,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
# TODO: Implement me
|
# TODO: Implement me
|
||||||
# return ''
|
# return ''
|
||||||
|
|
||||||
|
@neediface(-1)
|
||||||
def GetSignalStrength(self, iwconfig=None):
|
def GetSignalStrength(self, iwconfig=None):
|
||||||
""" Get the signal strength of the current network.
|
""" Get the signal strength of the current network.
|
||||||
|
|
||||||
@@ -514,7 +518,6 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
The signal strength.
|
The signal strength.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return -1
|
|
||||||
buff = get_iw_ioctl_result(self.iface, SIOCGIWSTATS)
|
buff = get_iw_ioctl_result(self.iface, SIOCGIWSTATS)
|
||||||
strength = ord(buff[2])
|
strength = ord(buff[2])
|
||||||
max_strength = self._get_max_strength()
|
max_strength = self._get_max_strength()
|
||||||
@@ -545,6 +548,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
values = struct.unpack(fmt, data)
|
values = struct.unpack(fmt, data)
|
||||||
return values[12]
|
return values[12]
|
||||||
|
|
||||||
|
@neediface(-100)
|
||||||
def GetDBMStrength(self, iwconfig=None):
|
def GetDBMStrength(self, iwconfig=None):
|
||||||
""" Get the dBm signal strength of the current network.
|
""" Get the dBm signal strength of the current network.
|
||||||
|
|
||||||
@@ -552,13 +556,13 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
The dBm signal strength.
|
The dBm signal strength.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return -100
|
|
||||||
buff = get_iw_ioctl_result(self.iface, SIOCGIWSTATS)
|
buff = get_iw_ioctl_result(self.iface, SIOCGIWSTATS)
|
||||||
if not buff:
|
if not buff:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return str((ord(buff[3]) - 256))
|
return str((ord(buff[3]) - 256))
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetCurrentNetwork(self, iwconfig=None):
|
def GetCurrentNetwork(self, iwconfig=None):
|
||||||
""" Get the essid of the current network.
|
""" Get the essid of the current network.
|
||||||
|
|
||||||
@@ -566,7 +570,6 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
The current network essid.
|
The current network essid.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return ""
|
|
||||||
buff = get_iw_ioctl_result(self.iface, SIOCGIWESSID)
|
buff = get_iw_ioctl_result(self.iface, SIOCGIWESSID)
|
||||||
if not buff:
|
if not buff:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -143,6 +143,25 @@ def IsValidWpaSuppDriver(driver):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def neediface(default_response):
|
||||||
|
""" A decorator for only running a method if self.iface is defined.
|
||||||
|
|
||||||
|
This decorator is wrapped around Interface methods, and will
|
||||||
|
return a provided default_response value if self.iface is not
|
||||||
|
defined.
|
||||||
|
|
||||||
|
"""
|
||||||
|
def wrapper(func):
|
||||||
|
def newfunc(self, *args, **kwargs):
|
||||||
|
if not self.iface:
|
||||||
|
return default_response
|
||||||
|
return func(self, *args, **kwargs)
|
||||||
|
newfunc.__dict__ = func.__dict__
|
||||||
|
newfunc.__doc__ = func.__doc__
|
||||||
|
newfunc.__module__ = func.__module__
|
||||||
|
return newfunc
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class BaseInterface(object):
|
class BaseInterface(object):
|
||||||
@@ -304,6 +323,7 @@ class BaseInterface(object):
|
|||||||
self.kdesu_cmd = self._find_program_path("kdesu")
|
self.kdesu_cmd = self._find_program_path("kdesu")
|
||||||
self.ktsuss_cmd = self._find_program_path("ktsuss")
|
self.ktsuss_cmd = self._find_program_path("ktsuss")
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def Up(self):
|
def Up(self):
|
||||||
""" Bring the network interface up.
|
""" Bring the network interface up.
|
||||||
|
|
||||||
@@ -311,12 +331,12 @@ class BaseInterface(object):
|
|||||||
True
|
True
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
cmd = 'ifconfig ' + self.iface + ' up'
|
cmd = 'ifconfig ' + self.iface + ' up'
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def Down(self):
|
def Down(self):
|
||||||
""" Take down the network interface.
|
""" Take down the network interface.
|
||||||
|
|
||||||
@@ -324,12 +344,12 @@ class BaseInterface(object):
|
|||||||
True
|
True
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
cmd = 'ifconfig ' + self.iface + ' down'
|
cmd = 'ifconfig ' + self.iface + ' down'
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def SetAddress(self, ip=None, netmask=None, broadcast=None):
|
def SetAddress(self, ip=None, netmask=None, broadcast=None):
|
||||||
""" Set the IP addresses of an interface.
|
""" Set the IP addresses of an interface.
|
||||||
|
|
||||||
@@ -339,9 +359,6 @@ class BaseInterface(object):
|
|||||||
broadcast -- broadcast address in dotted quad form
|
broadcast -- broadcast address in dotted quad form
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface:
|
|
||||||
return
|
|
||||||
|
|
||||||
for val in [ip, netmask, broadcast]:
|
for val in [ip, netmask, broadcast]:
|
||||||
if not val:
|
if not val:
|
||||||
continue
|
continue
|
||||||
@@ -452,6 +469,7 @@ class BaseInterface(object):
|
|||||||
print 'DHCP connection failed'
|
print 'DHCP connection failed'
|
||||||
return 'dhcp_failed'
|
return 'dhcp_failed'
|
||||||
|
|
||||||
|
@neediface
|
||||||
def StartDHCP(self):
|
def StartDHCP(self):
|
||||||
""" Start the DHCP client to obtain an IP address.
|
""" Start the DHCP client to obtain an IP address.
|
||||||
|
|
||||||
@@ -460,8 +478,6 @@ class BaseInterface(object):
|
|||||||
_check_dhcp_result for the possible values.
|
_check_dhcp_result for the possible values.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
|
|
||||||
cmd = self._get_dhcp_command('connect')
|
cmd = self._get_dhcp_command('connect')
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
|
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
|
||||||
@@ -477,16 +493,16 @@ class BaseInterface(object):
|
|||||||
else:
|
else:
|
||||||
print 'ERROR no dhclient found!'
|
print 'ERROR no dhclient found!'
|
||||||
|
|
||||||
|
@neediface
|
||||||
def ReleaseDHCP(self):
|
def ReleaseDHCP(self):
|
||||||
""" Release the DHCP lease for this interface. """
|
""" Release the DHCP lease for this interface. """
|
||||||
if not self.iface: return False
|
|
||||||
cmd = self._get_dhcp_command("release")
|
cmd = self._get_dhcp_command("release")
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface
|
||||||
def DelDefaultRoute(self):
|
def DelDefaultRoute(self):
|
||||||
""" Delete only the default route for a device. """
|
""" Delete only the default route for a device. """
|
||||||
if not self.iface: return False
|
|
||||||
if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]:
|
if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]:
|
||||||
cmd = '%s route del default dev %s' % (self.ip_cmd, self.iface)
|
cmd = '%s route del default dev %s' % (self.ip_cmd, self.iface)
|
||||||
elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]:
|
elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]:
|
||||||
@@ -497,6 +513,7 @@ class BaseInterface(object):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface
|
||||||
def SetDNS(self, dns1=None, dns2=None, dns3=None,
|
def SetDNS(self, dns1=None, dns2=None, dns3=None,
|
||||||
dns_dom=None, search_dom=None):
|
dns_dom=None, search_dom=None):
|
||||||
""" Set the DNS of the system to the specified DNS servers.
|
""" Set the DNS of the system to the specified DNS servers.
|
||||||
@@ -511,7 +528,6 @@ class BaseInterface(object):
|
|||||||
search_dom -- DNS search domain
|
search_dom -- DNS search domain
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
resolv_params = ""
|
resolv_params = ""
|
||||||
if dns_dom:
|
if dns_dom:
|
||||||
resolv_params += 'domain %s\n' % dns_dom
|
resolv_params += 'domain %s\n' % dns_dom
|
||||||
@@ -541,9 +557,9 @@ class BaseInterface(object):
|
|||||||
resolv.write(resolv_params + "\n")
|
resolv.write(resolv_params + "\n")
|
||||||
resolv.close()
|
resolv.close()
|
||||||
|
|
||||||
|
@neediface
|
||||||
def FlushRoutes(self):
|
def FlushRoutes(self):
|
||||||
""" Flush network routes for this device. """
|
""" Flush network routes for this device. """
|
||||||
if not self.iface: return False
|
|
||||||
if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]:
|
if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]:
|
||||||
cmds = ['%s route flush dev %s' % (self.ip_cmd, self.iface)]
|
cmds = ['%s route flush dev %s' % (self.ip_cmd, self.iface)]
|
||||||
elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]:
|
elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]:
|
||||||
@@ -555,6 +571,7 @@ class BaseInterface(object):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface
|
||||||
def SetDefaultRoute(self, gw):
|
def SetDefaultRoute(self, gw):
|
||||||
""" Add a default route with the specified gateway.
|
""" Add a default route with the specified gateway.
|
||||||
|
|
||||||
@@ -562,7 +579,6 @@ class BaseInterface(object):
|
|||||||
gw -- gateway of the default route in dotted quad form
|
gw -- gateway of the default route in dotted quad form
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return
|
|
||||||
if not misc.IsValidIP(gw):
|
if not misc.IsValidIP(gw):
|
||||||
print 'WARNING: Invalid gateway found. Aborting!'
|
print 'WARNING: Invalid gateway found. Aborting!'
|
||||||
return False
|
return False
|
||||||
@@ -570,6 +586,7 @@ class BaseInterface(object):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetIP(self, ifconfig=""):
|
def GetIP(self, ifconfig=""):
|
||||||
""" Get the IP address of the interface.
|
""" Get the IP address of the interface.
|
||||||
|
|
||||||
@@ -577,7 +594,6 @@ class BaseInterface(object):
|
|||||||
The IP address of the interface in dotted quad form.
|
The IP address of the interface in dotted quad form.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return ""
|
|
||||||
if not ifconfig:
|
if not ifconfig:
|
||||||
cmd = 'ifconfig ' + self.iface
|
cmd = 'ifconfig ' + self.iface
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
@@ -586,6 +602,7 @@ class BaseInterface(object):
|
|||||||
output = ifconfig
|
output = ifconfig
|
||||||
return misc.RunRegex(ip_pattern, output)
|
return misc.RunRegex(ip_pattern, output)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def VerifyAPAssociation(self, gateway):
|
def VerifyAPAssociation(self, gateway):
|
||||||
""" Verify assocation with an access point.
|
""" Verify assocation with an access point.
|
||||||
|
|
||||||
@@ -597,6 +614,7 @@ class BaseInterface(object):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
return misc.LaunchAndWait(cmd)
|
return misc.LaunchAndWait(cmd)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def IsUp(self, ifconfig=None):
|
def IsUp(self, ifconfig=None):
|
||||||
""" Determines if the interface is up.
|
""" Determines if the interface is up.
|
||||||
|
|
||||||
@@ -604,7 +622,6 @@ class BaseInterface(object):
|
|||||||
True if the interface is up, False otherwise.
|
True if the interface is up, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
flags_file = '/sys/class/net/%s/flags' % self.iface
|
flags_file = '/sys/class/net/%s/flags' % self.iface
|
||||||
try:
|
try:
|
||||||
flags = open(flags_file, "r").read().strip()
|
flags = open(flags_file, "r").read().strip()
|
||||||
@@ -643,6 +660,7 @@ class BaseWiredInterface(BaseInterface):
|
|||||||
"""
|
"""
|
||||||
BaseInterface.__init__(self, iface, verbose)
|
BaseInterface.__init__(self, iface, verbose)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def GetPluggedIn(self):
|
def GetPluggedIn(self):
|
||||||
""" Get the current physical connection state.
|
""" Get the current physical connection state.
|
||||||
|
|
||||||
@@ -654,8 +672,6 @@ class BaseWiredInterface(BaseInterface):
|
|||||||
True if a link is detected, False otherwise.
|
True if a link is detected, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface:
|
|
||||||
return False
|
|
||||||
# check for link using /sys/class/net/iface/carrier
|
# check for link using /sys/class/net/iface/carrier
|
||||||
# is usually more accurate
|
# is usually more accurate
|
||||||
sys_device = '/sys/class/net/%s/' % self.iface
|
sys_device = '/sys/class/net/%s/' % self.iface
|
||||||
@@ -753,6 +769,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
""" Sets the wpa_driver. """
|
""" Sets the wpa_driver. """
|
||||||
self.wpa_driver = _sanitize_string(driver)
|
self.wpa_driver = _sanitize_string(driver)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def SetEssid(self, essid):
|
def SetEssid(self, essid):
|
||||||
""" Set the essid of the wireless interface.
|
""" Set the essid of the wireless interface.
|
||||||
|
|
||||||
@@ -764,6 +781,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
if self.verbose: print str(cmd)
|
if self.verbose: print str(cmd)
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def GetKillSwitchStatus(self):
|
def GetKillSwitchStatus(self):
|
||||||
""" Determines if the wireless killswitch is enabled.
|
""" Determines if the wireless killswitch is enabled.
|
||||||
|
|
||||||
@@ -771,7 +789,6 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
True if the killswitch is enabled, False otherwise.
|
True if the killswitch is enabled, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
output = self.GetIwconfig()
|
output = self.GetIwconfig()
|
||||||
|
|
||||||
killswitch_pattern = re.compile('.*radio off', re.I | re.M | re.S)
|
killswitch_pattern = re.compile('.*radio off', re.I | re.M | re.S)
|
||||||
@@ -782,9 +799,9 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
|
|
||||||
return radiostatus
|
return radiostatus
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def GetIwconfig(self):
|
def GetIwconfig(self):
|
||||||
""" Returns the output of iwconfig for this interface. """
|
""" Returns the output of iwconfig for this interface. """
|
||||||
if not self.iface: return ""
|
|
||||||
cmd = "iwconfig " + self.iface
|
cmd = "iwconfig " + self.iface
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
return misc.Run(cmd)
|
return misc.Run(cmd)
|
||||||
@@ -893,6 +910,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
ap['encryption'] = False
|
ap['encryption'] = False
|
||||||
return ap
|
return ap
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def SetMode(self, mode):
|
def SetMode(self, mode):
|
||||||
""" Set the mode of the wireless interface.
|
""" Set the mode of the wireless interface.
|
||||||
|
|
||||||
@@ -900,7 +918,6 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
mode -- mode to set the interface to
|
mode -- mode to set the interface to
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
mode = _sanitize_string_strict(mode)
|
mode = _sanitize_string_strict(mode)
|
||||||
if mode.lower() == 'master':
|
if mode.lower() == 'master':
|
||||||
mode = 'managed'
|
mode = 'managed'
|
||||||
@@ -908,6 +925,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def SetChannel(self, channel):
|
def SetChannel(self, channel):
|
||||||
""" Set the channel of the wireless interface.
|
""" Set the channel of the wireless interface.
|
||||||
|
|
||||||
@@ -915,7 +933,6 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
channel -- channel to set the interface to
|
channel -- channel to set the interface to
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
if not channel.isdigit():
|
if not channel.isdigit():
|
||||||
print 'WARNING: Invalid channel found. Aborting!'
|
print 'WARNING: Invalid channel found. Aborting!'
|
||||||
return False
|
return False
|
||||||
@@ -924,6 +941,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def SetKey(self, key):
|
def SetKey(self, key):
|
||||||
""" Set the encryption key of the wireless interface.
|
""" Set the encryption key of the wireless interface.
|
||||||
|
|
||||||
@@ -931,11 +949,11 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
key -- encryption key to set
|
key -- encryption key to set
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
cmd = 'iwconfig %s key %s' % (self.iface, key)
|
cmd = 'iwconfig %s key %s' % (self.iface, key)
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def Associate(self, essid, channel=None, bssid=None):
|
def Associate(self, essid, channel=None, bssid=None):
|
||||||
""" Associate with the specified wireless network.
|
""" Associate with the specified wireless network.
|
||||||
|
|
||||||
@@ -945,7 +963,6 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
bssid -- bssid of the network
|
bssid -- bssid of the network
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
|
||||||
cmd = ['iwconfig', self.iface, 'essid', essid]
|
cmd = ['iwconfig', self.iface, 'essid', essid]
|
||||||
if channel and str(channel).isdigit():
|
if channel and str(channel).isdigit():
|
||||||
cmd.extend(['channel', str(channel)])
|
cmd.extend(['channel', str(channel)])
|
||||||
@@ -969,6 +986,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
return misc.RunRegex(key_pattern, misc.Run(cmd))
|
return misc.RunRegex(key_pattern, misc.Run(cmd))
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def Authenticate(self, network):
|
def Authenticate(self, network):
|
||||||
""" Authenticate with the specified wireless network.
|
""" Authenticate with the specified wireless network.
|
||||||
|
|
||||||
@@ -1026,6 +1044,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
if self.verbose: print ' '.join(cmd)
|
if self.verbose: print ' '.join(cmd)
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface([])
|
||||||
def GetNetworks(self):
|
def GetNetworks(self):
|
||||||
""" Get a list of available wireless networks.
|
""" Get a list of available wireless networks.
|
||||||
|
|
||||||
@@ -1203,12 +1222,14 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
cmd = 'wpa_cli -i' + self.iface + ' scan'
|
cmd = 'wpa_cli -i' + self.iface + ' scan'
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface(False)
|
||||||
def StopWPA(self):
|
def StopWPA(self):
|
||||||
""" Terminates wpa using wpa_cli"""
|
""" Terminates wpa using wpa_cli"""
|
||||||
cmd = 'wpa_cli -i %s terminate' % self.iface
|
cmd = 'wpa_cli -i %s terminate' % self.iface
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetBSSID(self, iwconfig=None):
|
def GetBSSID(self, iwconfig=None):
|
||||||
""" Get the MAC address for the interface. """
|
""" Get the MAC address for the interface. """
|
||||||
if not iwconfig:
|
if not iwconfig:
|
||||||
@@ -1221,6 +1242,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
bssid = misc.RunRegex(bssid_pattern, output)
|
bssid = misc.RunRegex(bssid_pattern, output)
|
||||||
return bssid
|
return bssid
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetCurrentBitrate(self, iwconfig=None):
|
def GetCurrentBitrate(self, iwconfig=None):
|
||||||
""" Get the current bitrate for the interface. """
|
""" Get the current bitrate for the interface. """
|
||||||
if not iwconfig:
|
if not iwconfig:
|
||||||
@@ -1233,6 +1255,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
bitrate = misc.RunRegex(bitrate_pattern, output)
|
bitrate = misc.RunRegex(bitrate_pattern, output)
|
||||||
return bitrate
|
return bitrate
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetOperationalMode(self, iwconfig=None):
|
def GetOperationalMode(self, iwconfig=None):
|
||||||
""" Get the operational mode for the interface. """
|
""" Get the operational mode for the interface. """
|
||||||
if not iwconfig:
|
if not iwconfig:
|
||||||
@@ -1247,6 +1270,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
opmode = opmode.strip()
|
opmode = opmode.strip()
|
||||||
return opmode
|
return opmode
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetAvailableAuthMethods(self, iwlistauth=None):
|
def GetAvailableAuthMethods(self, iwlistauth=None):
|
||||||
""" Get the available authentication methods for the interface. """
|
""" Get the available authentication methods for the interface. """
|
||||||
if not iwlistauth:
|
if not iwlistauth:
|
||||||
@@ -1276,6 +1300,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@neediface(-1)
|
||||||
def GetSignalStrength(self, iwconfig=None):
|
def GetSignalStrength(self, iwconfig=None):
|
||||||
""" Get the signal strength of the current network.
|
""" Get the signal strength of the current network.
|
||||||
|
|
||||||
@@ -1291,6 +1316,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
output = iwconfig
|
output = iwconfig
|
||||||
return self._get_link_quality(output)
|
return self._get_link_quality(output)
|
||||||
|
|
||||||
|
@neediface(-100)
|
||||||
def GetDBMStrength(self, iwconfig=None):
|
def GetDBMStrength(self, iwconfig=None):
|
||||||
""" Get the dBm signal strength of the current network.
|
""" Get the dBm signal strength of the current network.
|
||||||
|
|
||||||
@@ -1309,6 +1335,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
dbm_strength = misc.RunRegex(signaldbm_pattern, output)
|
dbm_strength = misc.RunRegex(signaldbm_pattern, output)
|
||||||
return dbm_strength
|
return dbm_strength
|
||||||
|
|
||||||
|
@neediface("")
|
||||||
def GetCurrentNetwork(self, iwconfig=None):
|
def GetCurrentNetwork(self, iwconfig=None):
|
||||||
""" Get the essid of the current network.
|
""" Get the essid of the current network.
|
||||||
|
|
||||||
@@ -1327,4 +1354,3 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
if network:
|
if network:
|
||||||
network = misc.to_unicode(network)
|
network = misc.to_unicode(network)
|
||||||
return network
|
return network
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user