Speed & ping tests from shell

Having *finally* got internet access in our new London flat, a month after we ordered it, I wanted to test the quality of the connection.

Downstream speed test

Use a compressed Linux kernel source for our speed test, taking advantage of how cURL annoyingly violates the UNIX “rule of silence”:

$ curl 'https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.3.tar.xz' > /dev/null

As the file is highly compressed, we are measuring raw bandwidth regardless of whether some part of our link has transparent compression. When the speed has stabilised, Ctrl+C to end the test.

Ping test

Run as root, required for ping flooding. Google probably won’t feel/notice/mind you ping-flooding their DNS servers:

$ ping -f -c 1000 -i 0.03 -W 1 -s 1350 -M do 8.8.8.8

Adjust 1350 to be slightly less than your MTU (1350 is a safe guess if you’re unsure). When the flood is complete (~10 seconds), you should receive your mean ping time, jitter, packet loss, etc.

Easy sandboxing for improved privacy and security

I have created a script to allow easy sandboxing of applications, by running them in a separate temporary single-use user account. By controlling which groups the temporary user is added to, one can control hardware access (e.g. audio, webcam, networking, etc). With permissions set correctly, one can protect their home folder from the prying eyes of dodgy closed-source software.

This script is not intended to be a *perfect* security solution – it is far from perfect, but will suffice in most situations where a little extra isolation is required.

There are two scripts:

The first script (sandbox) is used to launch a program in a sandbox. The second script (sandchrome) demonstrates this by launching an incognito chrome session in a sandbox, with access to audio explicitly granted.

g++ output formatter

Anyone who’s done much work with metaprogramming or heavy STL usage in C++ will be familiar with this:

g++ ugly output

While Clang’s output is often slightly less ugly than GCC, it’s still fairly cryptic.

To resolve this, I wrote a perl script which re-formats GCC output. Simply pipe your GCC output into the script, then optionally into less -R to get nicer output:

c++ pretty output

There are two files required, the actual formatter c++-color and a helper cxx-type-formatter specifically for data-types:

Put c++-color in somewhere in your $PATH and mark it executable, alter the require line to point to where you saved cxx-type-formatter then to use the formatter, pipe gcc/g++ into it:

# Example

$ g++ -std=c++14 -Wall -g *.cpp -o my-app    2>&1 | c++-color | less -R

It is important to pipe gcc’s STDERR stream into STDOUT with the 2>&1, otherwise the formatter can’t operate on it.

Happy debugging!