-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelnet.py
41 lines (37 loc) · 1.09 KB
/
telnet.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
37
38
39
40
41
import argparse
import getpass
import sys
import telnetlib
def main(user_info, command_list, output, host):
with open(output, "w") as f:
user_file = open(user_info, "r")
user = user_file.readline()
passwd = user_file.readline()
user_file.close()
tn = telnetlib.Telnet(host)
tn.read_until('login: ')
tn.write(user + '\n')
if passwd :
tn.read_until('Password: ')
tn.write(passwd + '\n')
command = open(command_list, "r")
while True :
cmd = command.readline()
if cmd == "":
break
tn.write(cmd + '\n')
f.write(host + '\n')
f.write(tn.read_all() + '\n')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("user_info",
help="user account and password")
parser.add_argument("command_list",
help="the command list you want to put")
parser.add_argument("output",
help="the path of the output file")
parser.add_argument("site_address",
help="the link the the site")
args = parser.parse_args()
main(args.user_info, args.command_list,
args.output, args.site_addr)