#!/usr/bin/env bash # rdns - Reverse DNS CGI # Author: Sean B. Palmer, inamidst.com case $QUERY_STRING in ip=*) IP=${QUERY_STRING#ip=};; *) IP=${PATH_INFO#/};; esac function header() { echo Content-Type: $1 echo } function doHomepage() { header text/html cat <Reverse DNS

This script enables you to look up the DNS for any given IP. See also: source.

Sean B. Palmer
EOF } function doRedirect() { echo Status: 301 echo Content-Type: text/html echo Location: "http://inamidst.com/services/rdns/$IP" echo echo 'redirect' } function doReverseDNS() { header text/plain dig -x "$IP" | \ grep -iA 1 'ANSWER SECTION' | tail -n 1 | \ sed 's/ / /g' | cut -f 5 | sed 's/\.$//' } if [ "$QUERY_STRING" ] then doRedirect elif [ "$IP" ] then doReverseDNS else doHomepage fi