Python 错误:X() 需要 1 个参数(给了 8 个)
我正在尝试制作一个匿名FTP扫描器,但我在调用函数X时遇到了一个错误。我定义的函数X只接收一个参数,也就是IP地址。如果我不使用循环,而是一个一个地发送IP,这段代码就能正常工作。
错误信息是:X() 需要一个参数(但给了8个)。
from ftplib import FTP
import ipcalc
from threading import Thread
def X (ip):
try:
ftp = FTP(ip)
x = ftp.login()
if 'ogged' in str(x):
print '[+] Bingo ! we got a Anonymous FTP server IP: ' +ip
except:
return
def main ():
global ip
for ip in ipcalc.Network('10.0.2.0/24'):
ip = str(ip)
t = Thread (target = X, args = ip)
t.start()
main ()
1 个回答
25
在创建 Thread
对象时,args
应该是一个参数的序列,但你传入的是一个字符串。这会导致 Python 遍历这个字符串,把每个字符都当作一个参数。
你可以使用一个只包含一个元素的元组:
t = Thread (target = X, args = (ip,))
或者使用一个列表:
t = Thread (target = X, args = [ip])