From 901074ea4e685abdbf1631ae89e76aea8767428d Mon Sep 17 00:00:00 2001 From: BlucyBlue Date: Sun, 20 Jan 2019 19:02:57 +0100 Subject: [PATCH] Function 'check_proxy', which checks anonimity of a signle proxy by anaylizing return headers received from a request using the proxy in question. --- load_proxies.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/load_proxies.py b/load_proxies.py index bfad7a83..45e826f4 100644 --- a/load_proxies.py +++ b/load_proxies.py @@ -19,4 +19,27 @@ def load_proxies_from_csv(path_to_list): csv_reader = csv.DictReader(csv_file) proxies = [Proxy(line['ip'],line['port'],line['protocol']) for line in csv_reader] - return proxies \ No newline at end of file + return proxies + + +""" +A function which test the proxy by attempting +to make a request to the designated website. + +We use 'wikipedia.org' as a test, since we can test the proxy anonymity +by check if the returning 'X-Client-IP' header matches the proxy ip. +""" + + +def check_proxy(proxy_ip, proxy_port, protocol): + full_proxy = f'{protocol}://{proxy_ip}:{proxy_port}' + proxies = {'http': full_proxy, 'https': full_proxy} + try: + r = requests.get('https://www.wikipedia.org',proxies=proxies, timeout=4) + return_proxy = r.headers['X-Client-IP'] + if proxy_ip==return_proxy: + return True + else: + return False + except Exception: + return False \ No newline at end of file