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
import getpass
import telnetlib
from time import localtime, strftime
HOST = "172.21.148.149"
tn = telnetlib.Telnet(HOST.rstrip())
tn.read_until(b"Username: ")
tn.write(b"neon\n")
tn.read_until(b"Password: ")
tn.write(b"0248616\n")
print(tn.read_some().decode('ascii'))
tn.write(b"en\n")
tn.read_until(b"Password: ")
tn.write(b"0248616\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.writelines(mass)
tn.close();
file.close();