Created
August 16, 2022 15:40
-
-
Save voglster/d40a68355b4f333a885ea1887d6d3c47 to your computer and use it in GitHub Desktop.
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 telnetlib | |
import sys | |
from loguru import logger | |
from data import tank_monitor_lookup | |
def get_data_telnet(host: str, port: int): | |
command = f"\x01I20100".encode("ascii") | |
read_until = f"I20100".encode("ascii") | |
logger.info(f"Attempting to connect to {host}:{port} as a tls_350") | |
with telnetlib.Telnet( | |
host, | |
port, | |
timeout=10, | |
) as tn: | |
logger.info(f"Connected, Writing status command") | |
tn.write(command) | |
logger.info(f"Waiting for response") | |
tn.read_until(read_until, timeout=10) | |
logger.info(f"Got response, parsing") | |
try: | |
response = ( | |
tn.read_until("\x03".encode("ascii"), 30).decode().replace("\x03", "") | |
) | |
except EOFError: | |
logger.info("Did not get response expected") | |
logger.info("Attempting to eager read remaining response") | |
response = tn.read_very_eager().decode().replace("\x03", "") | |
logger.info("Raw Response is:") | |
print(response) | |
logger.info("End Response") | |
return response | |
if __name__ == "__main__": | |
if len(sys.argv) not in [3, 4]: | |
print("usage: test_conn {atg_hostname} {port} [atg flavor]") | |
print( | |
f"atg flavor domain, optional: {list(tank_monitor_lookup.keys())} default tls_350" | |
) | |
sys.exit(1) | |
host = sys.argv[1] | |
port = int(sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment