-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathssh.py
38 lines (28 loc) · 897 Bytes
/
ssh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import getpass
from netmiko import ConnectHandler
"""
Main SSH module
"""
def run(hostname, port, username, password, command):
"""
Executes command on hostname:port with given username and password.
Returns output string.
"""
node = {
'device_type': 'linux',
'ip': hostname,
'username': username,
'password': password,
'port' : port, # optional, defaults to 22
'verbose': False, # optional, defaults to False
}
connection = ConnectHandler(**node)
output = connection.send_command(command)
connection.disconnect()
return output
def suwrap(password, command):
return " sudo -S <<< \"{}\" su -c '{}'".format(password, command)
def gethostnames():
return ["rc3-{}".format(i) for i in range(1, 24 + 1)]
def getpassword():
return getpass.getpass("rc3-admin password: \n")