Created
June 24, 2021 15:35
-
-
Save tubaman/70f07315dddcd70882640f6bf7e66f3f to your computer and use it in GitHub Desktop.
Use this in place of `import telnet` for telnet servers that can't handle fast interactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os,re,telnetlib,time | |
class SlowTelnet(telnetlib.Telnet): | |
"""Spoon feed slow telnet servers""" | |
def __init__(self, *args, delay=0.2, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.delay = delay | |
def read_until(self, *args, **kwargs): | |
buffer = super().read_until(*args, **kwargs) | |
time.sleep(self.delay) | |
return buffer | |
def write(self, buffer): | |
for b in [i.to_bytes(1, sys.byteorder) for i in buffer]: | |
super().write(b) | |
time.sleep(self.delay) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment