11

我正在尝试构建一个匿名 FTP 扫描程序,但我在调用函数 X 时遇到错误,我将 X 定义为仅接收 1 个参数,即 IP 地址,如果我不使用循环并发送相同的代码,则相同的代码有效IP 一个一个。

错误是: 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 ()
4

1 回答 1

25

构造Thread对象时,args应该是一系列参数,但您传入的是字符串。这会导致 Python 遍历字符串并将每个字符视为参数。

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

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

或列表:

t =  Thread (target = X, args = [ip])
于 2013-03-03T18:16:36.810 回答