Android and Linux

Wednesday, June 30, 2010

QR Codes

I'm going to start adding QR codes to scripts I post here. QR codes are neat, but I've never found much use for them until I realized Barcode Scanner has an option to copy text from QR codes to the clipboard. Cool.

Here is an example using my locate.sh script, and the preview from Barcode Scanner.





Note, there is no button in Barcode Scanner to save as a file, but if you hit the menu, there is an option to automatically save text to the clipboard. If that's turned on, you just scan the code then open a text editor and paste.

I'm not sure anyone will find any use for the codes, but getting the script to the phone is the number one problem users have with my iphone language deletion script. I get 100 hits a day to that page and it seems like 50% have trouble getting it on the phone. Too bad QR codes can only handle 4000 characters and that puppy is over 9700.

None of the online qr code generators work very well. I couldn't find any that encoded newlines so the whole script would end up being copied on one line. I finally decided to see what was available for Linux and ran across the qrencode command line utility which seems to work perfectly.

I'll be going back and adding them soon. EDIT: Done!

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