TotalFreedomBot/telnet.py

26 lines
862 B
Python
Raw Normal View History

2020-10-30 13:56:43 +00:00
import time
2020-10-31 02:06:25 +00:00
import checks
2020-10-30 13:56:43 +00:00
from telnetlib import Telnet
2020-10-31 02:06:25 +00:00
class telnet():
def __init__(self, ip, port, username, password):
self.ip = ip
self.port = port
self.username = username
2020-10-31 20:07:30 +00:00
self.password = password
2020-10-30 13:56:43 +00:00
2020-10-31 02:06:25 +00:00
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.')