FTP check

Fast Multi-threaded FTP Scanner

0

Votes

from datetime import datetime
import time
import threading
import random
###########################
import dns.resolver
import dns.reversename
import ftplib
import ipaddress

thread_list = []
no_ips_to_scan = 10000

now = datetime.now()
logfile = now.strftime('mylogfile_%H_%M_%d_%m_%Y.log')
f = open(logfile, "a")
f.write("#####################################################\n")
f.write("#####################################################\n")
f.write("#This is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; \n#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n")
f.write("#####################################################\n")
f.write("#####################################################\n")
f.write("#Last Modified:" + str(now.strftime("%Y-%m-%d %H:%M:%S")) + "\n")
f.write("#####################################################\n")
f.write("#####################################################\n")
f.close()

def worker(thread_no):
    f = open(logfile, "a")
    ip = ".".join(map(str, (random.randint(0, 255)
                            for _ in range(4))))
    try:
        n = dns.reversename.from_address(ip)
        reverse_PTR = str(dns.resolver.query(n, "PTR")[0])
    except BaseException:
        # woops, could not resolve PTR record!!
        f.close()
        return

    print("trying...." + str(reverse_PTR))
    f.write("trying...." + str(reverse_PTR) + "\n")

    files = []

    try:
        try:
            ftp = ftplib.FTP(ip, timeout=3)
            ftp.set_pasv(False)
            ftp.login("anonymous", "")
        except ftplib.error_perm as error:
            f.close()
            return
        files = ftp.nlst()
    except Exception as e:
        f.close()
        return

    if len(files) > 0:
        for file in files:
            f.write(str(file) + "\n")
    else:
        f.write("No files in dir")
        f.close()
        return

    f.write("##################################\n")
    f.write("##################################\n")
    f.write("##################################\n")
    f.close()


def debug_info(err_str):
    # Standard debugging function, pass it a string
    # print("-----------------DEBUG-----------------")
    f.write(str(time.strftime("%H:%M:%S")) +
            ":!!!DEBUG!!!:\n" + str(err_str) + "\n")
    # print("-----------------DEBUG-----------------")


for each in range(no_ips_to_scan):

    for thread_no in range(1):
        thread = threading.Thread(target=worker, args=(thread_no,))
        thread_list.append(thread)
        thread.start()

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote

Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

Advertise

DevOpsnipp.com © 2020

medium.png