Schlagwort-Archive: shell

ssm – SSH Shell Menu

SSH Shell Menu written in Python

Source: https://github.com/lanbugs/ssm

This is a small python script for a shell menu to manage and open ssh connections.

Requirements

  • python3
  • dialog
  • pythondialog

Installation

Install Debian packages and pip packages

apt install python3 python3-pip python3-setuptools dialog
pip3 install -r requirements.txt

Copy ssm to /usr/bin/local

cp ssm /usr/bin/local
chmod +x /usr/bin/local/ssm

Create connections.ini

Create folder in home directory and create connections.ini file.

mkdir ~/.ssm
cd ~/.ssm
touch connections.ini

For each server create a new section in the connections.ini file.

[example1]
description=Example1 Server
user=root
server=server1.example.org
port=22
options=
ssh_key=

You can use different ssh keys for each connection and you can define options for ssh command.

Use it!

ssm

Python: Snippet: SSH shell on Cisco devices

Mit dem Snippet können Kommandos auf einer Cisco Shell via SSH ausgeführt werden.

#!/usr/bin/env python

import paramiko
import sys


def send_string_and_wait_for_string(command, wait_string, should_print):
    shell.send(command)
  
    receive_buffer = ""

    while not wait_string in receive_buffer:
        receive_buffer += shell.recv(1024)

    if should_print:
        print receive_buffer

    return receive_buffer

client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("10.62.62.10", username="testuser", password="testpasswd", look_for_keys=False, allow_agent=False)

shell = client.invoke_shell()
send_string_and_wait_for_string("", "#", False)
send_string_and_wait_for_string("terminal length 0\n", "#", False)
output=send_string_and_wait_for_string("show logging\n", "#", False)
print output
client.close()

Mehr Infos / Quelle: http://blog.timmattison.com/archives/2014/06/25/automating-cisco-switch-interactions/