def test_geo(self): p = Proxy('127.0.0.1', '80') self.assertEqual(p.geo.code, '--') self.assertEqual(p.geo.name, 'Unknown') p = Proxy('8.8.8.8', '80') self.assertEqual(p.geo.code, 'US') self.assertEqual(p.geo.name, 'United States')
def test_geo(): p = Proxy('127.0.0.1', '80') assert p.geo.code == '--' assert p.geo.name == 'Unknown' p = Proxy('8.8.8.8', '80') assert p.geo.code == 'US' assert p.geo.name == 'United States'
def test_schemes(self): p = Proxy('127.0.0.1', '80') p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) self.assertEqual(p.schemes, ('HTTP', 'HTTPS')) p = Proxy('127.0.0.1', '80') p.types['HTTPS'] = None self.assertEqual(p.schemes, ('HTTPS',)) p = Proxy('127.0.0.1', '80') p.types.update({'SOCKS4': None, 'SOCKS5': None}) self.assertEqual(p.schemes, ('HTTP', 'HTTPS'))
def test_repr(): p = Proxy('8.8.8.8', '80') p._runtimes = [1, 3, 3] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) assert repr(p) == '<Proxy US 2.33s [HTTP: Anonymous, HTTPS] 8.8.8.8:80>' p = Proxy('4.4.4.4', '8080') p.types.update({'SOCKS4': None, 'SOCKS5': None}) assert repr(p) == '<Proxy US 0.00s [SOCKS4, SOCKS5] 4.4.4.4:8080>' p = Proxy('127.0.0.1', '3128') assert repr(p) == '<Proxy -- 0.00s [] 127.0.0.1:3128>'
def test_repr(self): p = Proxy('8.8.8.8', '80') p._runtimes = [1, 3, 2] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) self.assertEqual(repr(p), '<Proxy US 2.00s [HTTP: Anonymous, HTTPS] 8.8.8.8:80>') p.types.clear() p.types.update({'SOCKS4': None, 'SOCKS5': None}) self.assertEqual(repr(p), '<Proxy US 2.00s [SOCKS4, SOCKS5] 8.8.8.8:80>') p = Proxy('127.0.0.1', '80') self.assertEqual(repr(p), '<Proxy -- 0.00s [] 127.0.0.1:80>')
def test_schemes(): p = Proxy('127.0.0.1', '80') p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) assert p.schemes == ('HTTP', 'HTTPS') p = Proxy('127.0.0.1', '80') p.types['HTTPS'] = None assert p.schemes == ('HTTPS',) p = Proxy('127.0.0.1', '80') p.types.update({'SOCKS4': None, 'SOCKS5': None}) assert p.schemes == ('HTTP', 'HTTPS')
def test_repr(): p = Proxy('8.8.8.8', '80') p._runtimes = [1, 3, 3] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) assert repr( p ) == '<Proxy geo:US avg:2.33s err:0 req:3 [HTTP: Anonymous, HTTPS] 8.8.8.8:80>' p = Proxy('4.4.4.4', '8080') p.types.update({'SOCKS4': None, 'SOCKS5': None}) assert repr( p ) == '<Proxy geo:US avg:0.00s err:0 req:0 [SOCKS4, SOCKS5] 4.4.4.4:8080>' p = Proxy('127.0.0.1', '3128') assert repr(p) == '<Proxy geo:-- avg:0.00s err:0 req:0 [] 127.0.0.1:3128>'
def setUp(self): self.proxy = Proxy('127.0.0.1', '80') self.proxy.ngtr = 'SOCKS4' # Socks4Ngtr() self._send = patch.object(Proxy, 'send') self._recv = patch.object(Proxy, 'recv') self.send = self._send.start() self.recv = self._recv.start()
def test_as_json_w_geo(): p = Proxy('8.8.8.8', '3128') p._runtimes = [1, 3, 3] p.types.update({'HTTP': 'Anonymous', 'HTTPS': None}) json_tpl = { 'host': '8.8.8.8', 'port': 3128, 'geo': { 'country': { 'code': 'US', 'name': 'United States', }, }, 'types': [ { 'type': 'HTTP', 'level': 'Anonymous' }, { 'type': 'HTTPS', 'level': '' }, ], 'avg_resp_time': 2.33, 'error_rate': 0, } assert p.as_json() == json_tpl
def setUp(self): self.proxy = Proxy('127.0.0.1', '80') self.proxy.ngtr = 'CONNECT:25' # Connect25Ngtr() self._send = patch.object(Proxy, 'send') self._recv = patch.object(Proxy, 'recv') self.send = self._send.start() self.recv = self._recv.start()
def proxy(mocker): proxy = Proxy('127.0.0.1', '80', timeout=0.1) mocker.patch.multiple(proxy, send=mocker.DEFAULT, recv=mocker.DEFAULT, connect=mocker.DEFAULT) yield proxy mocker.stopall()
def setUp(self): self.proxy = Proxy('127.0.0.1', '80') self.proxy.ngtr = 'HTTPS' # HttpsNgtr() self._send = patch.object(Proxy, 'send') self._recv = patch.object(Proxy, 'recv') self._connect = patch.object(Proxy, 'connect') self.send = self._send.start() self.recv = self._recv.start() self.connect = self._connect.start()
async def test_create_with_ip(self): self.assertIsInstance(await Proxy.create('127.0.0.1', '80'), Proxy) self.assertTrue(Proxy('127.0.0.1', '80')) with self.assertRaises(ValueError): await Proxy.create('127.0.0.1', '65536') await Proxy.create('256.0.0.1', '80') self.assertRaises(ValueError, Proxy, '256.0.0.1', '80') self.assertRaises(ValueError, Proxy, '127.0.0.1', '65536')
def __init__(self, bot): self.bot = bot self.proxypath = 'data/tourney/proxyfile.txt' self.goodproxy = [] + proxies_list with open(self.proxypath, 'r') as f: for line in f: asplit = line.split(':') self.goodproxy.append(Proxy(host=asplit[0], port=asplit[1])) print("{} proxies were loaded".format(len(self.goodproxy))) self.path = 'data/tourney/settings.json' self.settings = dataIO.load_json(self.path) self.auth = dataIO.load_json('cogs/auth.json') self.queue = asyncio.Queue() self.broker = Broker(self.queue) self.proxylist = deque(self.goodproxy) self.goodproxy = [ ] # Proxies get saved once, then have to earn the right to stay again self.lastTag = '0'
def test_as_json_wo_geo(): p = Proxy('127.0.0.1', '80') p.log('MSG', time.time(), ProxyConnError) p.stat['requests'] = 4 json_tpl = { 'host': '127.0.0.1', 'port': 80, 'geo': { 'country': {'code': '--', 'name': 'Unknown'}, 'region': {'code': 'Unknown', 'name': 'Unknown'}, 'city': 'Unknown', }, 'types': [], 'avg_resp_time': 0, 'error_rate': 0.25, } assert p.as_json() == json_tpl
def test_log(log): p = Proxy('127.0.0.1', '80') msg = 'MSG' stime = time.time() err = ProxyConnError assert p.get_log() == [] assert p._runtimes == [] with log(logger.name, level='DEBUG') as cm: p.log(msg) p.ngtr = 'HTTP' p.log(msg) assert ('INFO', msg, 0) in p.get_log() assert ('HTTP', msg, 0) in p.get_log() assert len(p.stat['errors']) == 0 assert p._runtimes == [] assert cm.output == [ 'DEBUG:proxybroker:127.0.0.1:80 [INFO]: MSG; Runtime: 0.00', 'DEBUG:proxybroker:127.0.0.1:80 [HTTP]: MSG; Runtime: 0.00', ] p.log(msg, stime, err) p.log(msg, stime, err) assert len(p.stat['errors']) == 1 assert sum(p.stat['errors'].values()) == 2 assert p.stat['errors'][err.errmsg] == 2 assert round(p._runtimes[-1], 2) == 0.0 len_runtimes = len(p._runtimes) p.log(msg + 'timeout', stime) assert len(p._runtimes) == len_runtimes msg = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do' p.log(msg) last_msg = p.get_log()[-1][1] cropped = msg[:60] + '...' assert last_msg == cropped
def test_log(self): p = Proxy('127.0.0.1', '80') msg = 'MSG' stime = time.time() err = ProxyConnError self.assertEqual(p.get_log(), []) self.assertEqual(p._runtimes, []) with self.assertLogs(log.name, level='DEBUG') as cm: p.log(msg) p.ngtr = 'HTTP' p.log(msg) self.assertIn(('INFO', msg, 0), p.get_log()) self.assertIn(('HTTP', msg, 0), p.get_log()) self.assertEqual(len(p.stat['errors']), 0) self.assertEqual(p._runtimes, []) self.assertEqual( cm.output, ['DEBUG:proxybroker:127.0.0.1:80 [INFO]: MSG; Runtime: 0.00', 'DEBUG:proxybroker:127.0.0.1:80 [HTTP]: MSG; Runtime: 0.00']) p.log(msg, stime, err) p.log(msg, stime, err) self.assertEqual(len(p.stat['errors']), 1) self.assertEqual(sum(p.stat['errors'].values()), 2) self.assertEqual(p.stat['errors'][err.errmsg], 2) self.assertAlmostEqual(p._runtimes[-1], 0.0, places=1) len_runtimes = len(p._runtimes) p.log(msg + 'timeout', stime) self.assertEqual(len(p._runtimes), len_runtimes) msg = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do' p.log(msg) last_msg = p.get_log()[-1][1] cropped = msg[:60] + '...' self.assertEqual(last_msg, cropped)
def proxy(): proxy = Proxy('127.0.0.1', '80', timeout=0.1) proxy._reader['conn'] = StreamReader() return proxy
def test_ngtr(): p = Proxy('127.0.0.1', '80') p.ngtr = 'HTTPS' assert isinstance(p.ngtr, HttpsNgtr) assert p.ngtr._proxy is p
def setUp(self): self.proxy = Proxy('127.0.0.1', '80') self.proxy.ngtr = 'HTTP' # HttpNgtr()
def test_error_rate(): p = Proxy('127.0.0.1', '80') p.log('Error', time.time(), ProxyConnError) p.log('Error', time.time(), ProxyConnError) p.stat['requests'] = 4 assert p.error_rate == 0.5
def test_ngtr(self): p = Proxy('127.0.0.1', '80') p.ngtr = 'HTTPS' self.assertIsInstance(p.ngtr, HttpsNgtr) self.assertIs(p.ngtr._proxy, p)
import asyncio import random import json from cogs.utils import checks from .utils.dataIO import dataIO import os from fake_useragent import UserAgent from proxybroker import Broker, Proxy from collections import deque creditIcon = "https://i.imgur.com/TP8GXZb.png" credits = "Bot by GR8 | Titan" proxies_list = [ Proxy(host="94.249.160.49", port=6998), Proxy(host="93.127.128.41", port=7341), Proxy(host="107.175.43.100", port=6858), Proxy(host="64.44.18.31", port=3691), Proxy(host="172.82.173.100", port=5218), Proxy(host="172.82.177.111", port=3432), Proxy(host="45.43.219.185", port=2461), Proxy(host="45.43.218.82", port=3577), Proxy(host="195.162.4.111", port=4762), Proxy(host="173.211.31.3", port=8053) ] # Converts maxPlayers to Cards def getCards(maxPlayers): if maxPlayers == 50: return 25
def test_avg_resp_time(): p = Proxy('127.0.0.1', '80') assert p.avg_resp_time == 0.0 p._runtimes = [1, 3, 4] assert p.avg_resp_time == 2.67
def test_avg_resp_time(self): p = Proxy('127.0.0.1', '80') self.assertEqual(p.avg_resp_time, 0.0) p._runtimes = [1, 3, 2] self.assertEqual(p.avg_resp_time, 2.0)
def setUp(self): self.proxy = Proxy('127.0.0.1', '80', timeout=0.1) self.proxy._reader['conn'] = StreamReader()