def execute_command(self, command): """Execute command on ASA and return output""" try: stdin, stdout, stderr = self.ssh_client.exec_command(command) output = stdout.read().decode('utf-8') error = stderr.read().decode('utf-8') if error: self.logger.warning(f"Command error: {error}") return output except Exception as e: self.logger.error(f"Command execution failed: {str(e)}") return None
class CiscoASADownloader: def (self, hostname, username, password, port=22): self.hostname = hostname self.username = username self.password = password self.port = port self.ssh_client = None self.setup_logging() cisco asa 5506-x download
# Create output directory os.makedirs(args.output, exist_ok=True) exist_ok=True) def backup_asa(self
def backup_asa(self, destination_path): """Complete backup of ASA configuration and important files""" self.logger.info("Starting complete ASA backup...") # Create timestamped backup directory timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") backup_dir = os.path.join(destination_path, f"asa_backup_{self.hostname}_{timestamp}") os.makedirs(backup_dir, exist_ok=True) backups = [] # Download configurations running_config = self.download_running_config(backup_dir) if running_config: backups.append(running_config) startup_config = self.download_startup_config(backup_dir) if startup_config: backups.append(startup_config) # Download crypto info crypto = self.download_crypto_keys(backup_dir) if crypto: backups.append(crypto) # List flash files for reference flash_list = self.list_flash_files() if flash_list: flash_file = os.path.join(backup_dir, "flash_listing.txt") with open(flash_file, 'w') as f: f.write(flash_list) backups.append(flash_file) # Create manifest file manifest = os.path.join(backup_dir, "BACKUP_MANIFEST.txt") with open(manifest, 'w') as f: f.write(f"ASA Backup created on: {datetime.now()}\n") f.write(f"Hostname: {self.hostname}\n") f.write(f"Backup files:\n") for file in backups: f.write(f" - {os.path.basename(file)}\n") self.logger.info(f"Complete backup saved to: {backup_dir}") return backup_dir "flash_listing.txt") with open(flash_file