Пример #1
0
def main():
    host, port = '127.0.0.1', 8888  # by default

    loop = asyncio.get_event_loop()

    types = [('HTTP', 'High'), 'HTTPS', 'CONNECT:80']
    codes = [200, 301, 302]

    broker = Broker(max_tries=1, loop=loop)

    # Broker.serve() also supports all arguments that are accepted
    # Broker.find() method: data, countries, post, strict, dnsbl.
    broker.serve(host=host,
                 port=port,
                 types=types,
                 limit=10,
                 max_tries=3,
                 prefer_connect=True,
                 min_req_proxy=5,
                 max_error_rate=0.5,
                 max_resp_time=8,
                 http_allowed_codes=codes,
                 backlog=100)

    urls = [
        'http://httpbin.org/get', 'https://httpbin.org/get',
        'http://httpbin.org/redirect/1', 'http://httpbin.org/status/404'
    ]

    proxy_url = 'http://%s:%d' % (host, port)
    loop.run_until_complete(get_pages(urls, proxy_url))

    broker.stop()
Пример #2
0
def main():
    host, port = '127.0.0.1', 30003  # by default

    loop = asyncio.get_event_loop()

    types = ['HTTP', 'HTTPS']
    codes = [200]

    broker = Broker(max_tries=1, loop=loop)

    # Broker.serve() also supports all arguments that are accepted
    # Broker.find() method: data, countries, post, strict, dnsbl.
    broker.serve(host=host, port=port, types=types, limit=1000, max_tries=2,
                 prefer_connect=True, min_req_proxy=4, max_error_rate=0.25,
                 max_resp_time=4, http_allowed_codes=codes, backlog=100)


    # urls = ['https://translate.google.com/', 'https://google.com']
    #
    # proxy_url = 'http://%s:%d' % (host, port)
    #
    # # source, from_lang='auto', to_lang='en'
    # objs = [('i love my father', 'en', 'es'), ('so does my mother', 'en', 'es')]
    #
    # # res = translate(proxy_url=proxy_url, source=objs[0][0], from_lang='en', to_lang='es')
    #
    # # res = normal_google(proxy_url)
    # # print(res)
    #
    # sth = loop.run_until_complete(get_translates(proxy_url, objs))
    # # sth = loop.run_until_complete(get_pages(urls, proxy_url))
    # for fut in sth:
    #     print("return value is {}".format(fut.result()))
    broker.stop()
Пример #3
0
def main():
    loop = asyncio.get_event_loop()
    broker = Broker(max_tries=1, loop=loop)
    host, port = '127.0.0.1', 8080
    types = [('HTTP', 'High')]
    broker.serve(host=host,
                 port=port,
                 types=types,
                 limit=10,
                 max_tries=3,
                 prefer_connect=True,
                 min_req_proxy=5,
                 max_error_rate=0.5,
                 max_resp_time=8,
                 backlog=100,
                 countries=['VN'])
    loop.run_forever()
Пример #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-a",
                        "--addr",
                        help="specify host",
                        default='127.0.0.1')
    parser.add_argument("-p", "--port", help="specify port", default='8808')
    args = parser.parse_args()

    loop = asyncio.get_event_loop()
    types = ['HTTPS', 'HTTP']
    broker = Broker(max_tries=1, loop=loop)
    broker.serve(host=args.addr,
                 port=args.port,
                 types=types,
                 limit=10,
                 max_tries=3)
    loop.run_forever()
    broker.stop()
Пример #5
0
def start_proxy_server():
    host, port = '127.0.0.1', 8888  # by default
    types = [('HTTP', 'High'), 'HTTPS', 'CONNECT:80']
    codes = [200, 301, 302]

    broker = Broker(max_tries=1)

    # Broker.serve() also supports all arguments that are accepted
    # # Broker.find() method: data, countries, post, strict, dnsbl.
    broker.serve(host=host,
                 port=port,
                 types=types,
                 limit=100,
                 max_tries=3,
                 prefer_connect=True,
                 min_req_proxy=5,
                 max_error_rate=0.5,
                 max_resp_time=8,
                 http_allowed_codes=codes,
                 backlog=100)
Пример #6
0
def serve():
    loop = asyncio.get_event_loop()

    input_broker = {
        k: v
        for k, v in config["broker"].items() if v != "Default"
    }
    broker = Broker(**input_broker, loop=loop)

    input_serve = {k: v for k, v in config["serve"].items() if v != "Default"}
    types = [("HTTP", "High"), "HTTPS", "CONNECT:80"]
    broker.serve(**input_serve, types=types)

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        broker.stop()
    finally:
        loop.stop()
        loop.close()
Пример #7
0
def main():
    host, port = '127.0.0.1', 8888  # by default

    loop = asyncio.get_event_loop()

    types = [('HTTP', 'High'), 'HTTPS', 'CONNECT:80']
    codes = [200, 301, 302]

    broker = Broker(max_tries=1, loop=loop)

    # Broker.serve() also supports all arguments that are accepted
    # Broker.find() method: data, countries, post, strict, dnsbl.
    broker.serve(host=host, port=port, types=types, limit=10, max_tries=3,
                 prefer_connect=True, min_req_proxy=5, max_error_rate=0.5,
                 max_resp_time=8, http_allowed_codes=codes, backlog=100)

    urls = ['http://httpbin.org/get', 'https://httpbin.org/get',
            'http://httpbin.org/redirect/1', 'http://httpbin.org/status/404']

    proxy_url = 'http://%s:%d' % (host, port)
    loop.run_until_complete(get_pages(urls, proxy_url))

    broker.stop()
Пример #8
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import asyncio

from proxybroker import Broker

host, port = '127.0.0.1', 8888
loop = asyncio.get_event_loop()
types = ['HTTPS']
codes = [200, 301, 302]

countries = ['FR', 'DE', 'CA', 'NL', 'US']
broker = Broker(max_tries=1, loop=loop)

broker.serve(host=host,
             port=port,
             types=types,
             limit=10,
             max_tries=1,
             min_req_proxy=5,
             max_error_rate=0.5,
             max_resp_time=8,
             countries=countries,
             backlog=100)

loop.run_forever()