import getpass import telnetlib from time import localtime strftime HO

 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
import getpass
import telnetlib
from time import localtime, strftime
HOST = "xxx.xxx.xxx.xxx"
user = input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST.rstrip())
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
print(tn.read_some().decode('ascii'))
tn.write(b"en\n")
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"terminal length 0\n")
print(tn.read_some().decode('ascii'))
tn.write(b"show ip accounting checkpoint\n")
tn.read_until(b"CiscoNeo#",10)
tn.write(b"exit\n")
f = strftime("%d%b%Y_%H%M",localtime())
mass = tn.read_all().decode('ascii');
file = open(f+'.txt','w')
file.buffer_size = 100
file.writelines(mass)
for i in range(10):
print(mass[i])
tn.close();
file.close();