4062918ebb
All checks were successful
Deploy powerbar.ti Frontend Portal / Deploy-Tinance2-Frontend-Portal-Production (push) Successful in 6s
28 lines
836 B
Python
28 lines
836 B
Python
import telnetlib
|
|
import re
|
|
|
|
def get_baytech_status_outlet(hostname,port):
|
|
try:
|
|
# Create a Telnet object and connect to the host
|
|
tn = telnetlib.Telnet(hostname, port)
|
|
|
|
# Send the command you want to execute
|
|
command = "status"
|
|
tn.write(command.encode('ascii') + b"\r\n")
|
|
|
|
# Read the output until you receive the prompt or a timeout occurs
|
|
output = tn.read_until(b"<prompt>", timeout=5).decode('ascii')
|
|
# Close the Telnet connection
|
|
tn.close()
|
|
|
|
pattern = r"(\d+)\)\.\.\.Outlet\s+(\d+)\s+:\s+(\w+)"
|
|
outlets = {}
|
|
matches = re.findall(pattern, output)
|
|
for match in matches:
|
|
number = int(match[1])
|
|
status = match[2]
|
|
outlets[number] = status
|
|
|
|
return outlets
|
|
except:
|
|
return None
|