2021-04-13 20:06:16 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
|
|
|
|
oldexcepthook = sys.excepthook
|
|
|
|
def newexcepthook(type,value,traceback):
|
|
|
|
oldexcepthook(type,value,traceback)
|
|
|
|
input("Press ENTER to quit.")
|
|
|
|
sys.excepthook = newexcepthook
|
|
|
|
|
|
|
|
import os
|
|
|
|
p = os.path.join
|
|
|
|
pUp = os.path.dirname
|
|
|
|
s = False
|
|
|
|
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
|
|
|
s = os.path.realpath(sys.executable)
|
|
|
|
else:
|
|
|
|
s = os.path.realpath(__file__)
|
|
|
|
sp = pUp(s)
|
|
|
|
|
|
|
|
# script start
|
2021-04-13 18:33:16 +00:00
|
|
|
import subprocess
|
|
|
|
import socket
|
2021-04-13 20:06:16 +00:00
|
|
|
|
2021-04-13 23:09:34 +00:00
|
|
|
bufferSize = 1000 # buffer size in bytes
|
2021-04-13 18:33:16 +00:00
|
|
|
serverAddr = ("127.0.0.1",12000)
|
|
|
|
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
2021-04-13 23:09:34 +00:00
|
|
|
def listToCommand(lst):
|
|
|
|
cmd = ""
|
|
|
|
for arg in lst:
|
|
|
|
arg = arg.replace("\\","\\\\")
|
|
|
|
arg = arg.replace(",","\\,")
|
|
|
|
#arg = arg.replace('"','\\"')
|
|
|
|
#if " " in arg: arg = '"' +arg+ '"'
|
|
|
|
cmd += arg + ","
|
|
|
|
|
|
|
|
return cmd[:-1]
|
|
|
|
|
|
|
|
def makePayload(lst):
|
|
|
|
cmdText = listToCommand(lst)
|
|
|
|
cmdBytes = cmdText.encode("utf-8")
|
|
|
|
while len(cmdBytes) < 1000:
|
|
|
|
cmdBytes += b" "
|
|
|
|
return cmdBytes
|
|
|
|
|
2021-04-13 20:06:16 +00:00
|
|
|
def main():
|
|
|
|
connection.settimeout(15)
|
|
|
|
connection.connect(serverAddr)
|
2021-04-13 23:09:34 +00:00
|
|
|
connection.sendall(makePayload(sys.argv[1:]))
|
|
|
|
|
|
|
|
if sys.argv[1] == "watch":
|
|
|
|
while True:
|
|
|
|
data = connection.recv(bufferSize)
|
|
|
|
sys.stdout.buffer.write(data)
|
2021-04-13 20:06:16 +00:00
|
|
|
|
2021-04-13 23:09:34 +00:00
|
|
|
if sys.argv[1] == "broadcast":
|
|
|
|
while True:
|
|
|
|
data = sys.stdin.buffer.read(bufferSize)
|
|
|
|
connection.sendall(data)
|
2021-04-13 18:33:16 +00:00
|
|
|
|
2021-04-13 20:06:16 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|