Python错误:X()只接受1个参数(给定8个)

2024-05-23 16:02:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图建立一个匿名的FTP扫描器,但是我在调用函数X时出错,我定义X来接收一个参数,即ip地址,如果我不使用循环并逐个发送IPs,相同的代码也可以工作。

错误是:X()只接受1个参数(给定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 ()

Tags: infromimportip参数定义maindef
1条回答
网友
1楼 · 发布于 2024-05-23 16:02:05

构造Thread对象时,args应该是一个参数序列,但您传递的是一个字符串。这将导致Python遍历字符串并将每个字符作为参数处理。

可以使用包含一个元素的元组:

t =  Thread (target = X, args = (ip,))

或列表:

t =  Thread (target = X, args = [ip])

相关问题 更多 >