Skip to main content

A simple script to test if one or more HTTP proxies are working by fetching a webpage.

Project description

# proxytest

[![Build Status](https://travis-ci.org/yoleg/proxytest.svg?branch=master)](https://travis-ci.org/yoleg/proxytest)
[![PyPI version](https://badge.fury.io/py/proxytest.svg)](https://badge.fury.io/py/proxytest)

Simple command-line script to check if multiple proxies are up by fetching a webpage through each (in parallel).

But the *main* purpose of proxytest is to be a Python **coding sample**, so it has way more features than it needs. :)

It's also an excuse for me to play with Travis, pypi, and namespace packages.

## Installation:

Requires Python 3.4 or above.

```
python3 -m pip install proxytest
```

## Examples:

```
proxytest http://1.2.3.4:8080 http://1.2.3.4:8081

proxytest 1.2.3.4:8080-8081 # same as above

proxytest -v -n 10 --timeout 1 "http://user:pass@exampleproxy.cofm:3128" "111.222.333.444:8080-8082" "111.222.333.444:8085-8090"

proxytest "1.2.3.4:1234" --url="https://example.com" --print

proxytest --help

python3 -m proxytest --version
```

## Command-line Arguments:

```
$ proxytest --help
usage: proxytest [-h] [--version] [--agent AGENT]
[--backend {aiohttp,requests}] [--number NUMBER]
[--timeout TIMEOUT] [--url TEST_URL] [--workers WORKERS]
[--print] [--format PRINT_FORMAT] [--quiet] [--debug]
[--verbose]
PROXYHOST:STARTPORT[-ENDPORT] [PROXYHOST:STARTPORT[-ENDPORT]
...]

Test if one or more HTTP proxies are working by requesting a webpage through
each.

positional arguments:
PROXYHOST:STARTPORT[-ENDPORT]
The proxy host/ports to use. -ENDPORT is optional.
Example: 1.2.3.4:8080 1.2.3.4:8080-8090. Use "none" to
call the webpage directly.

optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--agent AGENT, -a AGENT
The user agent string to use. (default: random)
--backend {aiohttp,requests}, -b {aiohttp,requests}
The backend to use. Choose from: aiohttp, requests.
(default: aiohttp)
--number NUMBER, -n NUMBER
Number of times to test each proxy (default: 1)
--timeout TIMEOUT, -t TIMEOUT
Timeout in seconds for each request. (default: 2)
--url TEST_URL, -u TEST_URL
The URL of the webpage to get. (default:
'http://example.com/').
--workers WORKERS, -j WORKERS
Max number of concurrent requests. (default:
unlimited)

output:
--print, -p Print each webpage to stdout on a successful fetch.
--format PRINT_FORMAT, -f PRINT_FORMAT
The output format to use for --print. Placeholders:
duration, end_callback, error, finished, headers,
name, proxy_url, result, result_flat, start_callback,
started, url. (default: 'Content from {name}:
"{result_flat:.100}..."')
--quiet, -q Suppress logging. Overrides --debug and --verbose, but
--print will still work.
--debug, -d Enable debug logging to stderr. Overrides --verbose.
--verbose, -v Enable verbose logging to stderr.
```

## Backends:

Built-in backends:

* aiohttp - asyncio support (requires: `aiohttp`, Python >= 3.5.3)
* requests - useful for Python 3.4, supports HTTPS proxies (requires: `requests`)
* dummy - does not make any outgoing connections

Third-party extensions can add backends by using the `proxytest.backends` [namespace package](https://packaging.python.org/guides/packaging-namespace-packages/). See the `tests/` directory for an example.

If a backend's requirements have not been met, the `--help` description for the `--backend` option will show a list of recommended packages to install that would enable more backends.

## Output:

No output on success unless verbose or debug mode enabled.

## Exit codes:

* 0 - all proxy requests succeeded
* 1 - one or more proxy requests failed
* 2 - could not test proxies (e.g. due to input error or system error)

## History:

A client needed a script to periodically check the outgoing connections on a dozen or so private proxies. A search for "proxy test" in pypi found nothing relevant.

Normally, I would have just written a simple wrapper for an HTTP client with proxy support (such as httpie).

But instead, I grabbed the ~~excuse~~ opportunity to write a ~~coding sample~~ open source package that ~~might have a tiny chance of being useful~~ might be useful to someone else.

## Links:

Homepage: https://github.com/yoleg/proxytest

A list of free proxies that may be useful for testing (not verified or in any way associated with this project): https://hidemyna.me/en/proxy-list/


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proxytest-0.4.1.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

proxytest-0.4.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file proxytest-0.4.1.tar.gz.

File metadata

  • Download URL: proxytest-0.4.1.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for proxytest-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4c1b5f383b9a9f668c3c66b40abd27e8e707af617e3b1b92fb4209d29916e14b
MD5 83971f3f843675ace87c645df1abcd04
BLAKE2b-256 d54565e69c6143847cb2ad352b784a5c6ed23708437826e17e60d8c6e6440a9c

See more details on using hashes here.

File details

Details for the file proxytest-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: proxytest-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for proxytest-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 516b7b43e12b78cc7ef9aba205b5001c517392d90845369ea26e3d19f00370a6
MD5 694db6a2971f69fb216a4dbf7ea6f914
BLAKE2b-256 feec73c616f2b75436021826833a6c90479f57dc853ae0bc0d78b0d2ab1e9b52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page