tsproxy

Traffic-shaping SOCKS5 proxy

tsproxy provides basic latency, download and upload traffic shaping while only requiring user-level access (no root permissions required). It should work for basic browser testing but for protocol-level work it does not provide a suitable replacement for something like dummynet or netem.

tsproxy is monolithic and all of the functionality is in tsproxy.py. It is written expecting Python 2.7.

Usage

$ python tsproxy.py --rtt=<latency> --inkbps=<download bandwidth> --outkbps=<upload bandwidth>

Hit ctrl-C (or send a SIGINT) to exit

Example

$ python tsproxy.py --rtt=200 --inkbps=1600 --outkbps=768

Command-line Options

Option Alias Description
--rtt -r Latency in milliseconds (full round trip, half of the latency gets applied to each direction).
--inkbps -i Download Bandwidth (in 1000 bits/s - Kbps).
--outkbps -o Upload Bandwidth (in 1000 bits/s - Kbps).
--window -w Emulated TCP initial congestion window (defaults to 10).
--port -p SOCKS 5 proxy port (defaults to port 1080). Specifying a port of 0 will use a randomly assigned port.
--bind -b Interface address to listen on (defaults to localhost).
--desthost -d Redirect all outbound connections to the specified host (name or IP).
--mapports -m Remap outbound ports. Comma-separated list of original:new with as a wildcard. `--mapports '443:8443,:8080'`
--localhost -l Include connections already destined for localhost/127.0.0.1 in the host and port remapping.
--nodnscache -n Disable the internal DNS cache.
--flushdnscache -f Automatically flush the DNS cache 500ms after the last client disconnects.
--verbose -v Increase verbosity (specify multiple times for more). -vvvv for full debug output.

Runtime Options

The traffic shaping configuration can be changed dynamically at runtime by passing commands in through the console (or stdin). Each command is on a line, terminated with an end-of-line (\n).

All bandwidth and latency changes also carry an implied flush and clear out any pending data.

Docker

A Dockerfile is provided to allow Docker development workflow.

Also, an official image on Docker Hub is available from source via an Automated Build to enable use of tsproxy in Docker environments. You can run tsproxy without installing anything (other than Docker) by issuing:

docker run --rm -it -p 1080:1080 webpagetest/tsproxy [options...]

Configuring Chrome to use tsproxy

Add a --proxy-server command-line option.

--proxy-server="socks://localhost:1080"

Known Shortcomings/Issues