#!/bin/sh
#
# $Revision: 1.4 $ $Date: 2012-07-26 17:11:47-04 $
# $Source: /home/vogelke/bin/RCS/ipurl,v $
# $Host: sys7.com $
# $UUID: 9ff939c1-fd61-39ab-b90e-2959aebeffb5 $
#
#<ipurl: read a URL, write w3m command with IP address instead of host.

PATH=/bin:/usr/bin:/usr/local/bin
export PATH

die () {
    echo "$*" >& 2
    exit 1
}

case "$#" in
    0)  die "usage: $0 url" ;;
    *)  ;;
esac

case "$1" in
    *//*) ;;
    *)    url="http://$1" ;;
esac

h=`echo $url | cut -f3 -d/`
set X `dnsip $h`
shift

case "$#" in
    0)  echo host failed ;;
    *)  x=`echo "$url" | sed -e "s/$h/$2/"`; echo w3m \'$x\' ;;
esac

exit 0
