File tree 1 file changed +53
-0
lines changed
1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usb.Telnet(ip_addr, TELNET_PORT, TELNET_TIMEOUT)
2
+ import telnetlib
3
+ import time
4
+ import socket
5
+ import sys
6
+
7
+
8
+ TELNET_PORT = 23
9
+ TELNET_TIMEOUT = 6
10
+
11
+ def send_command (remote_conn , cmd ):
12
+ cmd = cmd .rstrip ()
13
+ remote_conn .write (cmd + '\n ' )
14
+ time .sleep (1 )
15
+ return remote_conn .read_very_eager ()
16
+
17
+
18
+ def login (remote_conn , username , password ):
19
+ output = remote_conn .read_until ("sername:" ,TELNET_TIMEOUT )
20
+ remote_conn .write (username + '\n ' )
21
+ output += remote_conn .read_until ("assword:" ,TELNET_TIMEOUT )
22
+ remote_conn .write (password + '\n ' )
23
+ return output
24
+
25
+ def telnet_connect (ip_addr ):
26
+ try :
27
+ return telnetlib .Telnet (ip_addr , TELNET_PORT , TELNET_TIMEOUT )
28
+ except socket .timeout :
29
+ sys .exit ("Connectio n timed-out." + '\n ' )
30
+
31
+ def main ():
32
+ ip_addr = '184.105.247.70'
33
+ username = 'pyclass'
34
+ password = '88newclass'
35
+
36
+ remote_conn = telnet_connect (ip_addr )
37
+ output = login (remote_conn , username , password )
38
+
39
+ time .sleep (1 )
40
+ output = remote_conn .read_very_eager ()
41
+
42
+ output += send_command (remote_conn , 'term len 0' )
43
+ output += send_command (remote_conn , 'show version' )
44
+
45
+ print output
46
+
47
+ remote_conn .close ()
48
+
49
+
50
+
51
+
52
+ if __name__ == '__main__' :
53
+ main ()
You can’t perform that action at this time.
0 commit comments