From f90d8ee1f4d4cb98f83f9d61d9f8a7f0dc32db92 Mon Sep 17 00:00:00 2001 From: ECHibiki Date: Sat, 9 Mar 2019 15:54:08 -0500 Subject: [PATCH] socks test implementation --- Main_Test.py | 42 --------- PingProxyClass.py | 267 ++++++++++++++++++++++++++++------------------------ experimental.py | 51 ++++++++++ perfect_proxies.txt | 11 --- proxies.txt | 25 +---- proxy_tests.txt | 44 +-------- sites.txt | 5 +- 7 files changed, 205 insertions(+), 240 deletions(-) delete mode 100644 Main_Test.py rewrite PingProxyClass.py (67%) create mode 100644 experimental.py rewrite proxies.txt (100%) rewrite proxy_tests.txt (100%) diff --git a/Main_Test.py b/Main_Test.py deleted file mode 100644 index cc9d6ac..0000000 --- a/Main_Test.py +++ /dev/null @@ -1,42 +0,0 @@ - -import PingProxyClass -import sys -from threading import * - -if __name__ == "__main__": - - ips = open('proxies.txt', 'r+') - ips = ips.read().split('\n') - sites = open('sites.txt', 'r+') - sites = sites.read().split('\n') - - threads = [] - - proxy_pinger = PingProxyClass.PingProxy() - proxy_pinger.timeout_sec = 60 - proxy_pinger.sites_to_test = sites - - for proxy in ips: - thread = Thread(target=proxy_pinger.test_proxy_conn, args=[str(proxy)]) - thread.start() - threads.append(thread) - - for thread in threads: - thread.join() - - # threads = [] - # - # proxy_pinger = PingProxyClass.PingProxy() - # proxy_pinger.timeout_sec = 60 - # proxy_pinger.sites_to_test = sites - # for i in range(0,30000): - # proxy_pinger.post_msg = proxy_pinger.post_msg + "0" - # for proxy in ips: - # thread = Thread(target=proxy_pinger.test_proxy_speed, args=[str(proxy)]) - # thread.start() - # threads.append(thread) - # - # for thread in threads: - # thread.join() - - input('Finished - Press anykey') \ No newline at end of file diff --git a/PingProxyClass.py b/PingProxyClass.py dissimilarity index 67% index d42c004..824033a 100644 --- a/PingProxyClass.py +++ b/PingProxyClass.py @@ -1,121 +1,146 @@ -import requests -import traceback -import time -import sys - -from threading import * - - -class PingProxy: - - timeout_sec = 60 - sites_to_test = list() - post_msg = "" - # successful_get = list() - # successful_post = list() - # upload_string = "" - lock = Lock() - - def add_responses_to_test_file(self, response_list, proxy, connection_type): - self.lock.acquire() - test_file = open("proxy_tests.txt", "a+") - test_file.write(proxy + "\t" + connection_type + "\n\t" + response_list.__str__() + "\n") - test_file.close() - - perfect = True - for response in response_list: - if response_list[response].find("Success") == -1: - perfect = False - break - if perfect: - perfect_file = open("perfect_proxies.txt", "a+") - perfect_file.write(proxy + "\t" + connection_type + "\n") - perfect_file.close() - self.lock.release() - - def test_proxy_conn(self, proxy=""): - if proxy == "" or proxy[:1] == "#": - return - proxy_details = proxy.split("\t") - proxy = proxy_details[0] + ":" + proxy_details[1] - print(proxy, end=" ") - http_req = proxy_details[2].lower() - print(http_req) - proxies = { - http_req: http_req + '://' + proxy - } - site_responses = dict() - for site in self.sites_to_test: - try: - req = requests.get(site, proxies=proxies, timeout=self.timeout_sec) - site_responses[site] = "Success" - print(str(proxies) + "success on " + site + " " + str(req.status_code)) - except requests.exceptions.ConnectTimeout: - print(str(proxies) + ' ConnectTimeout on ' + site) - site_responses[site] = "ConnectTimeout" - except requests.exceptions.ProxyError: - print(str(proxies) + ' ProxyError on ' + site) - site_responses[site] = "ProxyError" - except requests.exceptions.ReadTimeout: - print(str(proxies) + ' ReadTimeout on ' + site) - site_responses[site] = "ReadTimeout" - except requests.exceptions.SSLError: - print(str(proxies) + ' SSLError on ' + site) - site_responses[site] = "SSLError" - except IOError: - traceback.print_exc() - print(str(proxies) + ' IOError on ' + site) - site_responses[site] = "IOError" - except: - traceback.print_exc() - print(str(proxies) + ' ??? Error on ' + site) - site_responses[site] = "??? Error" - self.add_responses_to_test_file(site_responses, proxy, http_req) - - def test_proxy_speed(self, proxy): - if proxy == "" or proxy[:1] == "#": - return - proxy_details = proxy.split("\t") - proxy = proxy_details[0] + ":" + proxy_details[1] - print(proxy, end=" ") - http_req = proxy_details[2] - print(http_req) - proxies = { - http_req: http_req + '://' + proxy - } - site_responses = dict() - - post_msg_bytes = sys.getsizeof(self.post_msg) - - for site in self.sites_to_test: - try: - start_time = time.time() - req = requests.post(site, proxies=proxies, timeout=self.timeout_sec, data=self.post_msg) - end_time = time.time() - duration = end_time - start_time - proxy_speed = (int((post_msg_bytes / 1024) / duration * 100)) / 100 - duration = (int(duration * 100)) / 100 - site_responses[site] = "Success: Upload time " + str(duration) + " for "+ str(post_msg_bytes / 1024) + \ - " bytes (" + str(proxy_speed) + "kb/s)" - print(str(proxies) + "success on " + site) - except requests.exceptions.ConnectTimeout: - print(str(proxies) + ' ConnectTimeout on ' + site) - site_responses[site] = "ConnectTimeout" - except requests.exceptions.ProxyError: - print(str(proxies) + ' ProxyError on ' + site) - site_responses[site] = "ProxyError" - except requests.exceptions.ReadTimeout: - print(str(proxies) + ' ReadTimeout on ' + site) - site_responses[site] = "ReadTimeout" - except requests.exceptions.SSLError: - print(str(proxies) + ' SSLError on ' + site) - site_responses[site] = "SSLError" - except IOError: - traceback.print_exc() - print(str(proxies) + ' IOError on ' + site) - site_responses[site] = "IOError" - except: - traceback.print_exc() - print(str(proxies) + ' ??? Error on ' + site) - site_responses[site] = "??? Error" - self.add_responses_to_test_file(site_responses, proxy) +import requests +import traceback +import time +import sys +import socks + +from threading import * + + +class PingProxy: + + timeout_sec = 60 + sites_to_test = list() + post_msg = "" + # successful_get = list() + # successful_post = list() + # upload_string = "" + lock = Lock() + sock_type = {"socks4": socks.SOCKS4, "SOCKS4": socks.SOCKS4, "socks5": socks.SOCKS5, "SOCKS5": socks.SOCKS5} + + def add_responses_to_test_file(self, response_list, ip, port, connection_type): + self.lock.acquire() + proxy = ip + ":" + port + test_file = open("proxy_tests.txt", "a+") + test_file.write(proxy + "\t" + connection_type + "\n\t" + response_list.__str__() + "\n") + test_file.close() + + perfect = True + for response in response_list: + if response_list[response].find("Success") == -1: + perfect = False + break + if perfect: + perfect_file = open("perfect_proxies.txt", "a+") + perfect_file.write(proxy + "\t" + connection_type + "\n") + perfect_file.close() + self.lock.release() + + def test_proxy_conn(self, proxy=""): + if proxy == "" or proxy[:1] == "#": + return + proxy_details = proxy.split("\t") + ip = proxy_details[0] + port = proxy_details[1] + req_type = proxy_details[2].lower() + http_type = req_type.find("http") > -1 + sockn = None + proxies = None + if http_type: + proxy = ip + ":" + port + proxies = { + "http": "http://" + proxy, + "https": "https://" + proxy, + } + else: + sockn = socks.socksocket() + sockn.set_proxy(self.sock_type[req_type], str(ip), int(port)) + headers = b"GET" + + site_responses = dict() + for site in self.sites_to_test: + try: + if http_type: + assert sockn is None + req = requests.get(site, proxies=proxies, timeout=self.timeout_sec, verify=False) + print(req) + else: + assert proxies is None + sockn.connect((site, 80)) + sockn.sendall(headers) + print(sockn.recv(4096)) + site_responses[site] = "Success" + print(ip + ":" + port + " " + req_type + " " + "success on " + site) + except requests.exceptions.ConnectTimeout: + print(ip + ":" + port + " " + req_type + " " + ' requests.ConnectTimeout on ' + site) + site_responses[site] = "requests.ConnectTimeout" + except requests.exceptions.ProxyError: + print(ip + ":" + port + " " + req_type + " " + ' requests.ProxyError on ' + site) + site_responses[site] = "requests.ProxyError" + except requests.exceptions.ReadTimeout: + print(ip + ":" + port + " " + req_type + " " + ' requests.ReadTimeout on ' + site) + site_responses[site] = "requests.ReadTimeout" + except requests.exceptions.SSLError: + print(ip + ":" + port + " " + req_type + " " + ' requests.SSLError on ' + site) + site_responses[site] = "requests.SSLError" + except socks.ProxyConnectionError: + traceback.print_exc() + print(ip + ":" + port + " " + req_type + " " + ' socks.ProxyConnectionError on ' + site) + site_responses[site] = "socks.ProxyConnectionError Error" + except IOError: + traceback.print_exc() + print(ip + ":" + port + " " + req_type + " " + ' IOError on ' + site) + site_responses[site] = "IOError" + except: + traceback.print_exc() + print(ip + ":" + port + " " + req_type + " " + ' ??? Error on ' + site) + site_responses[site] = "??? Error" + self.add_responses_to_test_file(site_responses, ip, port, req_type) + + # def test_proxy_speed(self, proxy): + # if proxy == "" or proxy[:1] == "#": + # return + # proxy_details = proxy.split("\t") + # proxy = proxy_details[0] + ":" + proxy_details[1] + # print(proxy, end=" ") + # http_req = proxy_details[2] + # print(http_req) + # proxies = { + # http_req: http_req + '://' + proxy + # } + # site_responses = dict() + # + # post_msg_bytes = sys.getsizeof(self.post_msg) + # + # for site in self.sites_to_test: + # try: + # start_time = time.time() + # req = requests.post(site, proxies=proxies, timeout=self.timeout_sec, data=self.post_msg) + # end_time = time.time() + # duration = end_time - start_time + # proxy_speed = (int((post_msg_bytes / 1024) / duration * 100)) / 100 + # duration = (int(duration * 100)) / 100 + # site_responses[site] = "Success: Upload time " + str(duration) + " for "+ str(post_msg_bytes / 1024) + \ + # " bytes (" + str(proxy_speed) + "kb/s)" + # print(ip + ":" + port + " " + req_type + " " + "success on " + site) + # except requests.exceptions.ConnectTimeout: + # print(ip + ":" + port + " " + req_type + " " + ' ConnectTimeout on ' + site) + # site_responses[site] = "ConnectTimeout" + # except requests.exceptions.ProxyError: + # print(ip + ":" + port + " " + req_type + " " + ' ProxyError on ' + site) + # site_responses[site] = "ProxyError" + # except requests.exceptions.ReadTimeout: + # print(ip + ":" + port + " " + req_type + " " + ' ReadTimeout on ' + site) + # site_responses[site] = "ReadTimeout" + # except requests.exceptions.SSLError: + # print(ip + ":" + port + " " + req_type + " " + ' SSLError on ' + site) + # site_responses[site] = "SSLError" + # except IOError: + # traceback.print_exc() + # print(ip + ":" + port + " " + req_type + " " + ' IOError on ' + site) + # site_responses[site] = "IOError" + # except: + # traceback.print_exc() + # print(ip + ":" + port + " " + req_type + " " + ' ??? Error on ' + site) + # site_responses[site] = "??? Error" + # self.add_responses_to_test_file(site_responses, proxy) diff --git a/experimental.py b/experimental.py new file mode 100644 index 0000000..c67572b --- /dev/null +++ b/experimental.py @@ -0,0 +1,51 @@ + +import PingProxyClass + +from threading import * + + +def test_of_proxy_conn(): + threads = [] + ips = open('proxies.txt', 'r+') + ips = ips.read().split('\n') + sites = open('sites.txt', 'r+') + sites = sites.read().split('\n') + + proxy_pinger = PingProxyClass.PingProxy() + proxy_pinger.timeout_sec = 60 + proxy_pinger.sites_to_test = sites + + for proxy in ips: + thread = Thread(target=proxy_pinger.test_proxy_conn, args=[str(proxy)]) + thread.start() + threads.append(thread) + + for thread in threads: + thread.join() + + +def test_of_proxy_speed(): + threads = [] + ips = open('proxies.txt', 'r+') + ips = ips.read().split('\n') + sites = open('sites.txt', 'r+') + sites = sites.read().split('\n') + + proxy_pinger = PingProxyClass.PingProxy() + proxy_pinger.timeout_sec = 60 + proxy_pinger.sites_to_test = sites + for i in range(0,30000): + proxy_pinger.post_msg = proxy_pinger.post_msg + "0" + for proxy in ips: + thread = Thread(target=proxy_pinger.test_proxy_speed, args=[str(proxy)]) + thread.start() + threads.append(thread) + + for thread in threads: + thread.join() + + +if __name__ == "__main__": + + test_of_proxy_conn() + input('Finished') \ No newline at end of file diff --git a/perfect_proxies.txt b/perfect_proxies.txt index eee7f0d..e69de29 100644 --- a/perfect_proxies.txt +++ b/perfect_proxies.txt @@ -1,11 +0,0 @@ -36.67.90.163:45789 http -92.247.142.14:53281 http -176.31.141.22:21231 http -66.97.37.55:80 http -109.86.184.131:53032 http -186.249.213.101:53482 http -95.31.245.61:59868 http -34.73.62.46:3128 http -176.192.74.234:32590 http -95.31.196.55:52461 http -202.152.54.242:8080 http diff --git a/proxies.txt b/proxies.txt dissimilarity index 100% index 15356bc..7fe265d 100644 --- a/proxies.txt +++ b/proxies.txt @@ -1,22 +1,3 @@ -#IP [tab] Port [tab] HTTPS/HTTP [tab] whatever -36.67.90.163 45789 HTTP -176.31.141.22 21231 HTTP -92.247.142.14 53281 HTTP -170.81.141.249 55698 HTTPS -31.135.16.69 43876 HTTPS -103.76.15.238 57900 HTTPS -109.121.207.134 38383 HTTPS -103.229.247.202 32659 HTTPS -85.175.216.32 53281 HTTPS -853.175.216.32 53281 HTTPS -103.250.166.4 43291 HTTPS -95.31.196.55 52461 HTTP -34.73.62.46 3128 HTTP -176.192.74.234 32590 HTTP -109.86.184.131 53032 HTTP -95.31.245.61 59868 HTTP -188.17.152.172 40687 HTTPS -202.152.54.242 8080 HTTP -177.66.255.175 43413 HTTPS -66.97.37.55 80 HTTP -186.249.213.101 53482 HTTP \ No newline at end of file +#IP [tab] Port [tab] HTTPS/HTTP/SOCKS4/SOCKS5 [tab] whatever +193.150.121.70 1080 SOCKS4 +59.115.36.149 1080 SOCKS5 \ No newline at end of file diff --git a/proxy_tests.txt b/proxy_tests.txt dissimilarity index 100% index b3d2ed2..6cb9773 100644 --- a/proxy_tests.txt +++ b/proxy_tests.txt @@ -1,40 +1,4 @@ -36.67.90.163:45789 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -92.247.142.14:53281 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -176.31.141.22:21231 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -170.81.141.249:55698 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -31.135.16.69:43876 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -109.121.207.134:38383 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -103.229.247.202:32659 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -103.76.15.238:57900 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -853.175.216.32:53281 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -66.97.37.55:80 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -109.86.184.131:53032 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -186.249.213.101:53482 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -95.31.245.61:59868 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -34.73.62.46:3128 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -176.192.74.234:32590 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -95.31.196.55:52461 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -202.152.54.242:8080 http - {'https://stackoverflow.com': 'Success', 'https://www.google.com/': 'Success', 'https://verniy.xyz/': 'Success', 'https://kissu.moe/': 'Success'} -188.17.152.172:40687 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -177.66.255.175:43413 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} -103.250.166.4:43291 https - {'https://stackoverflow.com': 'ProxyError', 'https://www.google.com/': 'ProxyError', 'https://verniy.xyz/': 'ProxyError', 'https://kissu.moe/': 'ProxyError'} +59.115.36.149:1080 socks5 + {'https://kissu.moe': 'ProxyConnectionError Error'} +193.150.121.70:1080 socks4 + {'https://kissu.moe': 'IOError'} diff --git a/sites.txt b/sites.txt index 1038e6a..871b48e 100644 --- a/sites.txt +++ b/sites.txt @@ -1,4 +1 @@ -https://stackoverflow.com -https://www.google.com/ -https://verniy.xyz/ -https://kissu.moe/ \ No newline at end of file +https://kissu.moe \ No newline at end of file -- 2.11.4.GIT