Reformat SQL queries for readability

SQL queries are somewhat reformatted for readability.

Also go from Python string formatting to using basic parameterization
offered by MySQLdb.
Introduce optparse

Rely on optparse for getting options and arguments instead of directly
accessing sys.argv. This doesn't change much now but it's easier to add
options going forward.
Print error messages to stderr
Remove dependency on ipaddr

Instead of using the convenient functions of the ipaddr module to check
for a valid IP address, we build our own IP checker using the sockets
module which is included with Python by default, thus removing an
external dependency.
Add support for common PoPs

Rewrote a whole bunch of stuff along the way :)