This repository has been archived on 2026-07-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Rete-poc/main.py
T
2026-07-14 20:50:46 -06:00

112 lines
4.5 KiB
Python

import requests
import sys
import validators
import os
print("Rete by koffee.zip 2026")
exist = True
try:
if sys.argv[1] == "-v" or sys.argv[1] == "--version":
print("Rete 1.0 by koffee.zip 2026")
exit(0)
if sys.argv[1] == "-h" or sys.argv[1] == "--help":
print("Usage: Rete [arguments] [URLs]")
print("-h --help Shows this help page")
print("-f --file Lets you check URLs via a txt file.")
print("-v --version Shows program's current version")
exit(0)
if sys.argv[1] == "-f" or sys.argv[1] == "--file":
count = 0
passed = 0
failed = 0
with open(os.path.expanduser(sys.argv[2]), "r") as fp:
for line in fp:
if not validators.url(line.strip()):
exist = False
else:
exist = True
if exist == True:
try:
response = requests.get(line.strip(), timeout=1)
except:
exist = False
try:
if response.status_code == 200 or response.status_code == 403:
print(f"Passed: {line.strip()} Status Code: {response.status_code}")
with open("passed.txt", 'a') as file:
file.write(f"\n{line.strip()}")
response.status_code = None
passed += 1
elif exist == False:
print(f"Failed: {line.strip()} server was not found, invalid url, or timed out")
with open("failed.txt", 'a') as file:
file.write(f"\n{line.strip()}")
failed += 1
else:
print(f"Failed: {line.strip()} Error Code: {response.status_code}")
with open("failed.txt", 'a') as file:
file.write(f"\n{line.strip()}")
failed += 1
except Exception as e:
if exist == False:
print(f"Failed: {line.strip()} server was not found, invalid url, or timed out")
with open("failed.txt", 'a') as file:
file.write(f"\n{line.strip()}")
failed += 1
else:
print(e)
exit
with open(sys.argv[2], 'r') as file:
line_count = sum(1 for line in file)
print("====================================")
print(f"{failed}/{line_count} URLs have failed.")
print(f"{passed}/{line_count} URLs have passed")
print("You can see all the passed URLs in passed.txt and failed URLs in failed.txt")
else: # No arg here
passed = 0
failed = 0
for i in range(len(sys.argv) - 1):
if not validators.url(sys.argv[i + 1]):
exist = False
else:
exist = True
if exist == True:
try:
response = requests.get(sys.argv[i + 1], timeout=1)
except:
exist = False
try:
if response.status_code == 200 or response.status_code == 403:
print(f"Passed: {sys.argv[i + 1]} Status Code: {response.status_code}")
response.status_code = None
passed += 1
elif exist == False:
print(f"Failed: {sys.argv[i + 1]} server was not found, invalid url, or timed out")
failed += 1
else:
print(f"Failed: {sys.argv[i + 1]} Error Code: {response.status_code}")
failed += 1
except Exception as e:
if exist == False:
print(f"Failed: {sys.argv[i + 1]} server was not found, invalid url, or timed out")
failed += 1
else:
print(e)
print("====================================")
print(f"{failed}/{i + 1} URLs have failed.")
print(f"{passed}/{i + 1} URLs have passed")
except IndexError:
print("Usage: Rete [arguments] [URLs]")
print("-h --help Shows this help page")
print("-f --file Lets you check URLs via a txt file.")
print("-v --version Shows program's current version")