Пример #1
0
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
Пример #2
0
    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')
Пример #3
0
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'
Пример #4
0
    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"))
Пример #5
0
    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>")
Пример #6
0
    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>')
Пример #7
0
 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()
Пример #8
0
 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()
Пример #9
0
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()
Пример #10
0
 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()
Пример #11
0
    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')
Пример #12
0
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>'
Пример #13
0
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')
Пример #14
0
    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'))
Пример #15
0
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>'
Пример #16
0
 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'
Пример #17
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
Пример #18
0
 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)
Пример #19
0
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
Пример #20
0
def proxy():
    proxy = Proxy('127.0.0.1', '80', timeout=0.1)
    proxy._reader['conn'] = StreamReader()
    return proxy
Пример #21
0
def test_ngtr():
    p = Proxy('127.0.0.1', '80')
    p.ngtr = 'HTTPS'
    assert isinstance(p.ngtr, HttpsNgtr)
    assert p.ngtr._proxy is p
Пример #22
0
 def setUp(self):
     self.proxy = Proxy('127.0.0.1', '80')
     self.proxy.ngtr = 'HTTP'  # HttpNgtr()
Пример #23
0
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
Пример #24
0
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
Пример #25
0
    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)
Пример #26
0
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
Пример #27
0
 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)
Пример #28
0
 def setUp(self):
     self.proxy = Proxy('127.0.0.1', '80', timeout=0.1)
     self.proxy._reader['conn'] = StreamReader()
Пример #29
0
 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)
Пример #30
0
    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)
Пример #31
0
 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)