Android and Linux

Saturday, June 26, 2010

Another unix tool (poorly) imitated

Android doesn't have a whois command, so I hammered one out the best I could. Unfortunately, it looks up the info from the who.is website, which could potentially change and render this useless, and it currently only works with IP addresses. It's not perfect, but it's the only whois for Android I know of.

It can be done with domain names, but the output is different depending on the server the whois site gets the info from, and that makes it impossible to predict which lines to extract. I did put in a -p "please" option to semi-work with domain names. It will look up the IP address for the domain, then do a whois on the IP. It fails sometimes, which is why I used it as an option.

This will also be uploaded to the script section of the L.E.S. Linux Android app, which just had an update and is working with Froyo now.

#! /system/bin/sh
if test -z "$1"; then exec echo "USAGE: whois.sh ip_address, -p for please, --help for more info"; fi
case "$1" in

--help)
echo 'whois.sh by fubaya (a-more-common-hades.blogspot.com).
Another cheap imitation of a missing unix tool. This simply displays the output of a search on the who.is website.
It currently only works with IP addresses, however with the -p (please) option,
it can use the ping command to get the IP address then look up the whois information for that IP.'
;;

-p)
if echo $2 | grep -q [a-z]
then
ip=$(ping -c 1 ${2} | grep PING | awk '{ print $3 }' | tr -d "()")
if test -z $ip; then exec echo "Sorry, something went wrong with the ping lookup for this domain.
Try getting rid of the 'http://'"; fi
wget -q -O - http://who.is/whois-ip/ip-address/${ip}/ | sed -e 's/&nbsp;/ /g' -e 's#<[^>]*>##g' | awk 'BEGIN{ RS="Extended Info"}{gsub(/.*Domain Search/,"");print;exit}' | sed "/^$/{N
/^\n$/D
}"
else exec echo "I was looking for an alphabetic domain name but didn't see one and got confused. Exiting."
fi
;;

*)
if echo $1 | grep -q [a-z]
then exec echo "Sorry, this only works with IP addresses unless you specify the -p option. Please see --help first."; fi
wget -q -O - http://who.is/whois-ip/ip-address/${1}/ | sed -e 's/&nbsp;/ /g' -e 's#<[^>]*>##g' | awk 'BEGIN{ RS="Extended Info"}{gsub(/.*Domain Search/,"");print;exit}' | sed "/^$/{
N
/^\n$/D
}"
;;

esac
Copy whois.sh to your clipboard with this QR code:

Followers