-2

I am practicing website hacking and I have this script. I want it to save each finding in one file. It currently replaces what it found with the new finding.

import requests

def request(url):
    try:
        return requests.get("http://" + url)
    except requests.exceptions.ConnectionError:
        pass
    except requests.exceptions.InvalidURL:
        pass
    except requests.urllib3.exceptions.LocationParseError:
        pass


target_url = "192.168.1.39/mutillidae/"

with open("/home/kali/PycharmProjects/websitesub/common.txt", "r") as wordlist_file:
     for line in wordlist_file:
        word = line.strip()
        test_url = target_url + "/" + word
        response = request(test_url)
        if response:
            with open("/home/kali/PycharmProjects/websitesub/output.txt", "w") as f:
                f.write("DIR" + test_url)
                print("DIR" + test_url)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Cezar
  • 15
  • 1
  • 6

2 Answers2

0

you can define a new output filename every time you save the file for example add the count of file in the directory

dir_path = r'\home\kali\pycharmprojects\websitesub'
count = len([entry for entry in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, entry))])
filename = f"output+{count}.txt"
output_file= os.path.join(dirpath, filename)

if response:
       with open(output_file, 'w') as f:
             .....
tdelaney
  • 73,364
  • 6
  • 83
  • 116
-1

this should work

with open("data1.txt", "a", encoding="utf-8") as file:
    file.write(the thing you want to write)