Color Output Mainfile

This commit is contained in:
Lukas 2020-11-01 19:37:53 +01:00
parent bf3e38eaa2
commit 7883a82b11
3 changed files with 92 additions and 72 deletions

34
main.py
View File

@ -19,8 +19,8 @@ def initialize():
def readsites(sitepath=None):
print(f"{tools.heading('Checking Sitedata')}\n{tools.spacer}")
print(f"Checking Sitedata...\n{tools.spacer}")
dod = {}
if sitepath:
sitedir = sitepath
@ -31,37 +31,45 @@ def readsites(sitepath=None):
for sitefile in glob.glob(sitedir + r"\*.json"):
sfn = os.path.basename(sitefile)
site, ext = os.path.splitext(sfn)
print(f"Parsing {sfn}")
print(f"> {sfn}", end=" | ")
with open(sitefile, 'r') as f:
data = json.load(f)
print(f"data:{data}")
dod[site] = data
# print(f"DEBUG: {dod}")
print(tools.spacer)
def proxytest():
print(f"Creating Proxys...\n{tools.spacer}")
one = proxy.Proxy
one.name = "TEST PROXY"
one.usr = os.getenv("PROXYUSR")
one.pwd = os.getenv("PROXYPW")
one.url = os.getenv("PROXYURL")
one.port = os.getenv("PROXYPORT")
print(f"{tools.heading('Creating Proxy(s)')}\n{tools.spacer}")
one = proxy.Proxy(
name="One",
url=os.getenv("PROXYURL"),
port=os.getenv("PROXYPORT"),
usr=os.getenv("PROXYUSR"),
pwd=os.getenv("PROXYPW")
)
print(f"> {Fore.MAGENTA}{one.name}{Style.RESET_ALL} |"
f" {tools.keyword('PROXYIP')}({one.ip}) {tools.keyword('WORKING')}({one.isworking})")
# one.testurl("http://www.whatismyproxy.com/")
proxy.test(one)
# proxy.testurl(one, "http://www.whatismyproxy.com/")
print(tools.spacer)
def monitortest(n=1):
print(f"Creating {tools.keyword(n)} new Monitor(s)...\n{tools.spacer}")
print(f"{tools.heading(f'Creating Monitor(s)')}\n{tools.spacer}")
for i in range(0, n):
mon = monitor.Monitor()
mon.name = f"Monitor {i}"
mon.url = "test"
print(f"{Fore.MAGENTA}{mon.name}{Style.RESET_ALL} |"
print(f"> {Fore.MAGENTA}{mon.name}{Style.RESET_ALL} |"
f" {tools.keyword('URL')}({mon.url}) {tools.keyword('PROXY')}({mon.proxy})")
print(tools.spacer)

View File

@ -1,65 +1,72 @@
import requests
def testurl(proxy, url):
if proxy.isworking:
r = proxy.session.get(url)
data = r.text
print(data)
def test(proxy):
# print(f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}')
proxy.session = requests.Session()
url = "https://api.ipify.org/"
proxies = {
'http': f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}',
'https': f'http://{proxy.usr}:{proxy.pwd}@{proxy.url}:{proxy.port}'
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/86.0.4240.111 Safari/537.36'
}
try:
proxy.session.headers = headers
# Check incoming ip
r = proxy.session.get(url)
incoming = r.text
# Check proxied ip
proxy.session.proxies = proxies
r = proxy.session.get(url)
if r.status_code == 200:
proxy.ip = r.text
print(f"Proxied {incoming} to {proxy.ip}")
proxy.isworking = True
else:
print(r.text)
proxy.isworking = False
print(f"Statuscode: {r.status_code}\nGood Proxy: {proxy.isworking}")
except Exception as e:
print(f"Connection Error! (check Proxy settings)\n\n{e}")
proxy.isworking = False
class Proxy:
def __init__(self):
def __init__(self, name, url, port, usr=None, pwd=None):
self.name = None
self.url = None
self.port = None
self.usr = None
self.pwd = None
# Necessary
self.name = name
self.url = url
self.port = port
# Optional
self.usr = usr
self.pwd = pwd
# Created on selftest
self.incoming = None
self.ip = None
self.session = None
self.isworking = None
# Running Proxy selftest
self.test()
def test(self):
# print(f'http://{self.usr}:{self.pwd}@{self.url}:{self.port}')
self.session = requests.Session()
url = "https://api.ipify.org/"
proxies = {
'http': f'http://{self.usr}:{self.pwd}@{self.url}:{self.port}',
'https': f'http://{self.usr}:{self.pwd}@{self.url}:{self.port}'
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/86.0.4240.111 Safari/537.36'
}
try:
self.session.headers = headers
# Check incoming ip
r = self.session.get(url)
self.incoming = r.text
# Check proxied ip
self.session.proxies = proxies
r = self.session.get(url)
if r.status_code == 200:
self.ip = r.text
# print(f"DEBUG: Proxied {incoming} to {self.ip}")
self.isworking = True
else:
print(r.text)
self.isworking = False
# print(f"DEBUG: Statuscode: {r.status_code}\nDEBUG: Good Proxy: {self.isworking}")
except Exception as e:
print(f"Connection Error! (check proxy settings)\n\n{e}")
self.isworking = False
def testurl(self, url):
if self.isworking:
r = self.session.get(url)
data = r.text
print(data)

View File

@ -6,9 +6,14 @@ def clear():
os.system('cls' if os.name == 'nt' else 'clear')
def keyword(kwd):
kwd = f"{Fore.RED}{kwd}{Style.RESET_ALL}"
return kwd
def keyword(txt):
txt = f"{Fore.RED}{txt}{Style.RESET_ALL}"
return txt
def heading(txt):
txt = f"{Fore.YELLOW}{txt}{Style.RESET_ALL}"
return txt
init()