-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-1t.py
34 lines (28 loc) · 943 Bytes
/
4-1t.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
#! /usr/bin/env python
import paramiko
from getpass import getpass
from time import sleep
ip_addr = '184.105.247.71'
username = 'pyclass'
port = 22
password = getpass()
def main():
print "Connecting to: ", ip_addr, "\n"
remote_conn_pre = paramiko.SSHClient() # Create ssh client object
remote_conn_pre.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Accept unknown host keys
remote_conn_pre.connect(ip_addr, username=username, password=password,
look_for_keys=False, allow_agent=False, port=port)
remote_conn = remote_conn_pre.invoke_shell()
cmd = "show version\n"
print "Sending command: ", cmd, "\n"
bytesout = remote_conn.send(cmd)
sleep(1)
if bytesout:
shver = remote_conn.recv(5000)
else:
print ("No Data Returned\n")
shver = "0"
print "Here is the output:\n\n"
print shver
if __name__ == '__main__':
main()