-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssh.py
36 lines (31 loc) · 972 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
"""
========================================
Name:General Author: Lalevin Martin
Mailbox: [email protected]
Github: http://github.com/nacglalevin
Written in 2022-12-6
==================NACG==================
"""
import paramiko
import sys
try:
ip = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
except:
print "Usage: [ip] [username] [password]"
sys.exit(0)
def ssh_command(ip, user, passwd):
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, username=user, password=passwd)
sessions = client.get_transport().open_session()
if sessions.active:
command = raw_input("Enter command:")
sessions.exec_command(command)
print(sessions.recv(65565))
except KeyboardInterrupt:
sys.exit(0)
return
ssh_command(ip, username, password)