-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtelnet.py
More file actions
54 lines (42 loc) · 1.34 KB
/
telnet.py
File metadata and controls
54 lines (42 loc) · 1.34 KB
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
54
from __future__ import print_function
from tools import findServerAddr
from threading import Thread
import socket
import time
import traceback
sep = '-' * 30
print('TELNET')
print(sep)
def onServerFound(address):
address = (address[0], 23) # telnet port
while True:
try:
sock = socket.socket()
sock.settimeout(10)
sock.connect(address)
print('connected to %s:%d' % address)
sock.settimeout(3)
connected = True
print(sep)
print('\n')
while connected:
try:
buf = sock.recv(4096)
if buf is not None:
if len(buf) > 0 and buf[0] is not '\0': # keep-alive
print(buf, end='') # '\n' already in buf
else:
connected = False
except socket.timeout:
#traceback.print_exc()
connected = False
sock.close()
print ('\n')
print(sep)
print('disconnected')
except :
#traceback.print_exc()
sock.close()
time.sleep(2)
Thread(target = findServerAddr, args = (onServerFound, )).start()
while True: time.sleep(1)