Created
November 26, 2023 03:04
-
-
Save Moondarker/9f802d61340b988d25dbd01cad6a1390 to your computer and use it in GitHub Desktop.
upscmd python3 rewrite for telnetlib3
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
#!/usr/bin/python3 | |
import asyncio, telnetlib3 | |
import sys | |
user = "REPLACEME_UPS_USER" | |
pwd = "REPLACEME_UPS_PWD" | |
if len(sys.argv) == 2: | |
cmd = sys.argv[1] | |
else: | |
print("the ups command to issue is missing.") | |
print("example: upscmd.py beeper.enable") | |
exit(1) | |
async def main(): | |
reader, writer = await telnetlib3.open_connection('127.0.0.1', 3493) | |
writer.write("USERNAME {0}\n".format(user)) | |
response = await reader.readuntil(b"OK") | |
print("USERNAME cmd status: {0}".format(response.decode('ascii').strip())) | |
writer.write("PASSWORD {0}\n".format(pwd)) | |
response = await reader.readuntil(b"OK") | |
print("PASSWORD cmd status: {0}".format(response.decode('ascii').strip())) | |
writer.write("INSTCMD ups {0}\n".format(cmd)) | |
response = await reader.readuntil(b"OK") | |
print("INSTCMD cmd status: {0}".format(response.decode('ascii').strip())) | |
writer.write("LOGOUT\n") | |
writer.close() | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment