-
Notifications
You must be signed in to change notification settings - Fork 4
/
telnet.py
25 lines (21 loc) · 862 Bytes
/
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
import time
import checks
from telnetlib import Telnet
class telnet():
def __init__(self, ip, port, username, password):
self.ip = ip
self.port = port
self.username = username
self.password = password
def connect(self, *username):
self.session = Telnet(self.ip, self.port)
for x in username:
self.username = username[0]
if b'Username:' in self.session.read_until(b'Username:', timeout = 3):
time.sleep(0.5)
self.session.write(bytes(self.username, 'ascii') + b"\r\n")
if b'Password:' in self.session.read_until(b'Password:', timeout = 3):
time.sleep(0.5)
self.session.write(bytes(self.password, 'ascii') + b"\r\n")
else:
raise ConnectionError('Failed to establish telnet connection.')