def Disconnect(self, nettype, name, mac): """ Disconnect from the network. """ iface = self.iface # mac and name need to be strings if mac in (None, ''): mac = 'X' if name in (None, ''): name = 'X' misc.ExecuteScripts(wpath.predisconnectscripts, self.debug, extra_parameters=(nettype, name, mac)) if self.pre_disconnect_script: print 'Running pre-disconnect script' misc.ExecuteScript(expand_script_macros(self.pre_disconnect_script, 'pre-disconnection', mac, name), self.debug) iface.ReleaseDHCP() iface.SetAddress('0.0.0.0') iface.FlushRoutes() iface.FlushDNS() iface.Down() iface.Up() misc.ExecuteScripts(wpath.postdisconnectscripts, self.debug, extra_parameters=(nettype, name, mac)) if self.post_disconnect_script: print 'Running post-disconnect script' misc.ExecuteScript(expand_script_macros(self.post_disconnect_script, 'post-disconnection', mac, name), self.debug)
def run_script_if_needed(self, script, msg, bssid='wired', essid='wired'): """ Execute a given script if needed. Keyword arguments: script -- the script to execute, or None/'' if there isn't one. msg -- the name of the script to display in the log. """ if script: print 'Executing %s script' % (msg) misc.ExecuteScript(expand_script_macros(script, msg, bssid, essid), self.debug)