diff options
author | terminaldweller <thabogre@gmail.com> | 2021-05-14 18:14:50 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2021-05-14 18:14:50 +0000 |
commit | 6e528248414e330c9e25e81596ab47b8b8a5b701 (patch) | |
tree | e1aa41a7f3198eeac187e6177ec7d4a33db229d3 /mushi.py | |
download | scripts-6e528248414e330c9e25e81596ab47b8b8a5b701.tar.gz scripts-6e528248414e330c9e25e81596ab47b8b8a5b701.zip |
first commitmaster
Diffstat (limited to 'mushi.py')
-rwxr-xr-x | mushi.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/mushi.py b/mushi.py new file mode 100755 index 0000000..1f8a659 --- /dev/null +++ b/mushi.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +import argparse +import socket +import code +import readline +import signal +import sys + +def SigHandler_SIGINT(signum, frame): + print() + sys.exit(0) + +def SigHandler_Timeout(signum, frame): + print("mushi timed out.") + raise Exception("time out") + +class Argparser(object): + def __init__(self): + self.parser = argparse.ArgumentParser() + self.parser.add_argument("--bool", action="store_true", help="bool", default=False) + self.parser.add_argument("--dbg", action="store_true", help="debug", default=False) + + def parse(self, args): + self.args, self.rest = self.parser.parse_known_args(args) + +# write code here +def premain(argparser): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server_address = ("", 10111) + sock.connect(server_address) + msg = " ".join(argparser.rest) + sock.sendall(bytes(msg, "utf-8")) + output = sock.recv(4096) + out2 = [c for c in output.decode("utf-8") if c != "\0"] + print("".join(out2)) + sock.close() + +def main(argv): + argparser = Argparser() + argparser.parse(argv) + if argparser.args.dbg: + try: + premain(argparser) + except: + variables = globals().copy() + variables.update(locals()) + shell = code.InteractiveConsole(variables) + shell.interact(banner="DEBUG REPL") + else: + premain(argparser) + +if __name__ == "__main__": + main(sys.argv[1:]) |