-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremotexecute.py
More file actions
26 lines (22 loc) · 888 Bytes
/
Copy pathremotexecute.py
File metadata and controls
26 lines (22 loc) · 888 Bytes
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
__author__ = 'alexm'
#!/usr/bin/python
#import sys, os, base64, getpass, socket, traceback, termios, tty, select
import paramiko, getpass
serverList = ["127.0.0.1"] # Enter the server list ["serverip1","serverip2"]
command= raw_input("Command: ") # Enter command ps, df
userName= raw_input("User: ")
userPass=getpass.getpass("Password: ")
# loops trough the server list and executes the command
for server in serverList:
t = paramiko.Transport((server,22))
try:
t.connect(username=userName,password=userPass,hostkey=None)
except:
print (server + ": Bad password or login!")
t.close()
break
else:
ch = t.open_channel(kind = "session")
ch.exec_command(command)
if (ch.recv_ready):
print (server + ": " + ch.recv(1000))