Skip to main content

GoWitnessCleanup.py

This script takes a folder full of screenshots from Gowitness and renames them so the format is:

IP.ADDRESS.OF.ENDPOINT-PORTNUMBER-PROTOCOL.png

I just find that easier for looking through the folder and getting the info I need.

import os
import shutil
from datetime import datetime
import re

def rename_and_copy_files():
# Get current directory
current_dir = os.getcwd()

# Create timestamp folder
timestamp = datetime.now().strftime('%Y-%m-%d-%H%M-converted')
new_dir = os.path.join(current_dir, timestamp)
os.makedirs(new_dir, exist_ok=True)

# Process each file in the current directory
for filename in os.listdir(current_dir):
if not filename.endswith('.jpeg'):
continue

# Parse the original filename
match = re.match(r'(https?)---([0-9.]+)-(\d+)\.jpeg', filename)
if match:
protocol, ip, port = match.groups()

# Create new filename
new_filename = f"{ip}-{port}-{protocol}.jpeg"

# Copy file to new directory with new name
source = os.path.join(current_dir, filename)
destination = os.path.join(new_dir, new_filename)
shutil.copy2(source, destination)
print(f"Copied and renamed: {filename} -> {new_filename}")

if __name__ == "__main__":
rename_and_copy_files()

```