Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import paramiko
- import os
- import time
- from argparse import ArgumentParser
- parser = ArgumentParser()
- parser.add_argument(
- '-t', '--timer', help='timer in minutes', type=int, default=5)
- args = parser.parse_args()
- class FastTransport(paramiko.Transport):
- def __init__(self, sock):
- super(FastTransport, self).__init__(sock)
- self.channel_events = {}
- self.channels_seen = {}
- self._channel_counter = 1
- self.default_window_size = 65535
- self.default_max_packet_size = 34816
- self.use_compression()
- def download(ip, user, passwd, remote_file, local_file, port=22):
- try:
- print("Connecting...")
- transport = FastTransport((ip, port))
- transport.connect(username=user, password=passwd)
- sftp = paramiko.SFTPClient.from_transport(transport)
- print("Downloading...")
- sftp.get(remotepath=remote_file, localpath=local_file)
- sftp.close()
- transport.close()
- print("Download Success")
- except Exception as e:
- print(e)
- def remote_listdir(ip, user, passwd, port=22):
- print("Retreiving remote directory listing...")
- transport = FastTransport((ip, port))
- transport.connect(username=user, password=passwd)
- sftp = paramiko.SFTPClient.from_transport(transport)
- return sftp.listdir(path='/root/masscan_output/')
- def merge_files():
- print("Merging files...")
- with open('output.txt', 'a') as localfile:
- with open('temp_output.txt') as remotefile:
- localfile.writelines('{}\n'.format(remotefile))
- def remove_duplicates():
- print("Removing Duplicates")
- with open('output.txt') as f:
- data = set(f.read.splitlines())
- with open('output.txt', 'w') as f:
- f.writelines(data + '\n')
- def delete_temp_file():
- os.system('rm output_backup.txt')
- if __name__ == '__main__':
- os.system('touch output.txt')
- os.system('touch output_backup.txt')
- while True:
- for remote_file in remote_listdir(IP,USER,PASS):
- download('IP,USER,PASS,
- remote_file=remote_file, local_file='temp_output.txt')
- merge_files()
- remove_duplicates()
- delete_temp_file()
- time.sleep(args.timer * 60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement