Refined Proxy Module + Some Cleanup in Main File

This commit is contained in:
Lukas 2020-11-01 19:04:27 +01:00
parent 1f655deeb8
commit bf3e38eaa2
2 changed files with 55 additions and 28 deletions

36
main.py
View File

@ -18,11 +18,12 @@ def initialize():
init(autoreset=True)
def readsites(p=None):
def readsites(sitepath=None):
print(f"Checking Sitedata...\n{tools.spacer}")
dod = {}
if p:
sitedir = p
if sitepath:
sitedir = sitepath
else:
rootdir = os.path.dirname(os.path.abspath(__file__))
sitedir = rootdir + r"\sites"
@ -35,10 +36,12 @@ def readsites(p=None):
data = json.load(f)
dod[site] = data
print(dod)
# 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")
@ -47,22 +50,25 @@ def proxytest():
one.port = os.getenv("PROXYPORT")
proxy.test(one)
# proxy.testurl(one, "http://www.whatismyproxy.com/")
print(tools.spacer)
if __name__ == "__main__":
num_monitors = 10
initialize()
readsites()
proxytest()
tools.clear()
print(f"Creating {num_monitors} new Monitors...\n{tools.spacer}")
for i in range(0, num_monitors):
def monitortest(n=1):
print(f"Creating {tools.keyword(n)} new 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} |"
f" {tools.keyword('URL')}({mon.url}) {tools.keyword('PROXY')}({mon.proxy})")
print(tools.spacer)
if __name__ == "__main__":
tools.clear()
initialize()
readsites()
proxytest()
monitortest()

View File

@ -1,34 +1,53 @@
import requests
from requests.auth import HTTPProxyAuth
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}')
s = requests.Session()
url = "http://example.com"
proxies = {
'http': f'http://{proxy.url}:{proxy.port}',
'https': f'http://{proxy.url}:{proxy.port}'
}
auth = HTTPProxyAuth(proxy.usr, proxy.pwd)
proxy.session = requests.Session()
url = "https://api.ipify.org/"
s.proxies = proxies
s.auth = auth
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:
r = s.get(url)
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"{r.status_code} -> {proxy.isworking}")
print(f"Statuscode: {r.status_code}\nGood Proxy: {proxy.isworking}")
except Exception as e:
print(f"Connection error! (Check proxy)\n\n{e}")
print(f"Connection Error! (check Proxy settings)\n\n{e}")
proxy.isworking = False
@ -41,4 +60,6 @@ class Proxy:
self.port = None
self.usr = None
self.pwd = None
self.ip = None
self.session = None
self.isworking = None