Skip to content

Instantly share code, notes, and snippets.

@Allstreamer
Created April 19, 2022 18:36
Show Gist options
  • Save Allstreamer/0bc711d4d35ddb523df560425da76513 to your computer and use it in GitHub Desktop.
Save Allstreamer/0bc711d4d35ddb523df560425da76513 to your computer and use it in GitHub Desktop.
A script to Summarize a Snowflake(Tor Project) Log file
# This Script uses the following dependancies
# pip install nums_from_string
#
# To Run this script type:
# python snow.py <Log File Name>
#
# Example:
# python snow.py snow.log
#
# Written By Allstreamer_
# Licenced Under MIT
import nums_from_string
import sys
lines = []
with open(sys.argv[1], "r") as file:
lines = file.readlines()
lines = [row.strip() for row in lines]
lines = filter(lambda row: "In the" in row, lines)
lines = [row.split(",", 1)[1] for row in lines]
lines = list(filter(lambda row: not nums_from_string.get_nums(row)[0] == 0, lines))
connections = lines
connections = sum([nums_from_string.get_nums(row)[0] for row in connections])
lines = [row.split("Relayed")[1] for row in lines]
upload = [row.split(",")[0].strip() for row in lines]
# print("\n".join(upload))
# print(f"'{upload[4]}'")
download = [row.split(",")[1].strip()[:-1] for row in lines]
# print(download)
# print(f"'{download[4]}'")
def get_byte_count(log_lines):
byte_count = 0
for row in log_lines:
symbols = row.split(" ")
if symbols[2] == "B":
byte_count += int(symbols[1])
elif symbols[2] == "KB":
byte_count += int(symbols[1]) * 1024
elif symbols[2] == "MB":
byte_count += int(symbols[1]) * 1024 * 1024
elif symbols[2] == "GB":
byte_count += int(symbols[1]) * 1024 * 1024 * 1024
return byte_count
upload_gb = get_byte_count(upload) / 1024 / 1024 / 1024
download_gb = get_byte_count(download) / 1024 / 1024 / 1024
print(f"Served {connections} People with ↑ {round(upload_gb,4)} GB, ↓ {round(download_gb,4)} GB")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment