您的位置:首页 > 编程语言 > Python开发

可匿名登录FTP服务器扫描文件列表python程序

2016-09-26 09:15 537 查看
最近在Freebuf上看到有个人扫描了全球的ip地址,扫描出近80万可匿名登录的FTP服务器,下载下来后用python写了一个扫描文件列表的程序,不过效率比较慢,只当学习一下,没准会找到比较有意思的东西呢。

代码如下:

import ftplib
import threading
import time
import socket
def anonyLogin(ftpUrl,FileDest):
dirList = []
hostnames = open(ftpUrl, 'r')
OutPut = open(FileDest,'w+')
socket.setdefaulttimeout(4)
for line in hostnames:
hostname = line.strip('\n').strip('\r')
try:
ftp = ftplib.FTP(hostname)
ftp.login('anonymous')
print 'Succeed:'+str(hostname)

except Exception,e:continue
try:
dirList = ftp.nlst()
ftp.quit()
except Exception,e:
dirList = []
print str(e)
continue
if dirList != []:
print str(dirList)
OutPut.write(hostname + ':\n' + str(dirList) + '\n')

OutPut.close()
hostnames.close()
return

th = threading.Thread(target=anonyLogin,args=('openftp2.txt','openftp_file2.txt'))
th.start()


刚考试扫描的时候经常会出现卡死的情况,所以加了个socket连接默认时长socket.setdefaulttimeout(4),默认4秒没反应就跳过。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python