def update_proxy_settings(self, *args, **kwargs): """ When the network configuration changes, this updates the SOCKS proxy settings based the current IP address(es) """ # Open a SystemConfiguration preferences session: sc_prefs = SCPreferences() # We want to enable the server when our hostname is not on the corporate network: # BUG: This does not handle multi-homed systems well: current_address = socket.gethostbyname(socket.getfqdn()) new_state = not current_address.startswith('10.0.1.') logging.info("Current address is now %s: SOCKS proxy will be %s" % (current_address, "Enabled" if new_state else "Disabled")) try: sc_prefs.set_proxy(enable=new_state, protocol='SOCKS', server=self.socks_server, port=self.socks_port) sc_prefs.save() logging.info("Successfully updated SOCKS proxy setting") except RuntimeError, e: logging.error("Unable to set SOCKS proxy setting: %s" % e.message)
def update_proxy_settings(self, *args, **kwargs): """ When the network configuration changes, this updates the SOCKS proxy settings based the current IP address(es) """ # Open a SystemConfiguration preferences session: sc_prefs = SCPreferences() # We want to enable the server when our hostname is not on the corporate network: # BUG: This does not handle multi-homed systems well: current_address = socket.gethostbyname(socket.getfqdn()) new_state = not current_address.startswith('10.0.1.') logging.info( "Current address is now %s: SOCKS proxy will be %s" % ( current_address, "Enabled" if new_state else "Disabled" ) ) try: sc_prefs.set_proxy( enable=new_state, protocol='SOCKS', server=self.socks_server, port=self.socks_port ) sc_prefs.save() logging.info("Successfully updated SOCKS proxy setting") except RuntimeError, e: logging.error("Unable to set SOCKS proxy setting: %s" % e.message)
def network_changed(self, *args, **kwargs): # Open a SystemConfiguration preferences session: sc_prefs = SCPreferences() # We want to enable the server when our hostname is not on the corporate network: current_address = socket.gethostbyname(socket.getfqdn()) new_state = not current_address.startswith('128.36.') self.logger.info("Current address is now %s: SOCKS proxy will be %s" % (current_address, "Enabled" if new_state else "Disabled")) try: sc_prefs.set_proxy(enable=new_state, protocol='SOCKS', server=self.socks_server, port=self.socks_port) sc_prefs.save() os.system("killall ssh") self.logger.info("Successfully updated SOCKS proxy setting") except RuntimeError, e: self.logger.error("Unable to set SOCKS proxy setting: %s" % e.message)