Little Python utilities for systems hackers

Over the last few years, I've run into some systems problems enough times that spending 2 hours writing a simple script to solve the problem started looking appealing. Below are two examples.

These scripts are offered with neither restrictions (100% free!) nor guarantees. Use them/modify them as you like! And let me know if you found them useful — mail me at jd@z****.***.

Simple DNS Server

I wrote this for myself when I was frustrated that /etc/hosts doesn't support wildcards. It lets you specify arbitrary regexs to match hosts against and what IP to return. Unmatched hosts cause a "failure", letting whatever's looking up for you continue to the next, presumably real, DNS server — so you can run this locally and prepend 127.0.0.1 to your resolv.conf to it without affecting normal lookups.

Download simpledns.py. Patches/fixes/expansions welcome!

Sample usage:

$ python simpledns.py '^appjet\.info\.?$' 127.0.0.2 '^.*\.appjet\.info\.?$' 127.0.0.3

You can also put your mappings in /etc/dns-listing, as whitespace-separated (newline ok) pairs of regex and IP.

Simple Reverse Proxy

Don't want to set up squid? Yeah, I didn't either. This script uses the Host: header of new incoming HTTP connections to forward those connections to your custom backends. I wrote this script so that I could run apache (serving this page, among others) and appjet.jar (serving gallery.zamfi.net) on the same IP address. Yay ports!

Download revproxy.py. Patches/fixes/expansions welcome!

Sample usage:

$ python revproxy.py -p '^gallery\.zamfi\.net.?$' 127.0.0.1:8081 '.*' 127.0.0.1:8080

As with simpledns.py, you can put your mappings in a file, specifyable with "-f configFile".