-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectthreadtest.py
53 lines (31 loc) · 1.3 KB
/
connectthreadtest.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
42
43
44
45
46
47
48
49
50
51
52
53
def check_login():
import telnetlib
import time
server_address = "ducsuus.com"
server_port = 10011
server_id = "1"
server_password = "1jDWe8sF"
try:
command_list = ["login serveradmin " + server_password,
"use " + str(server_id),
"channellist"]
t = telnetlib.Telnet(server_address, str(server_port))
print("Details (in check_login()): " + str(server_address) + " " + str(server_port))
# Clear the console
t.read_very_eager()
for command in command_list:
t.write((command + "\n").encode())
time.sleep(1)
command_response = t.read_very_eager().decode()
# If this is command was not successful then return False, it failed
if command_response != "error id=0 msg=ok":
error_message = "command: " + command + " response: " + command_response
t.write(("quit\n").encode())
return error_message
t.write(("quit\n").encode())
except Exception as e:
print("An error occured in check_login() while trying to check the login details: " + str(e))
return False
# All details supplied work, the program can continue
return True
print(str(check_login()))