#!/bin/sh helpmsg() { echo "get_ip - determine external IP address" echo echo "Usage: $0 [option]" echo " -w, --webcm - use webcm CGI handler method [default]" echo " -d, --dsld - use showdsldstat method (use only with kernel 2.6 firmwares)" echo " -e, --extquery - use external site query method" echo " -?, --help - print this help message" echo } local ip="" local retval=0 case "$1" in ""|-w|--webcm) local pw=$(/bin/allcfgconv -C ar7 -c -o - | sed -ne '/^webui[[:space:]]*{/,/^}/{ /=/{s/[[:space:]]*=[[:space:]]*/=/;s/^[[:space:]]*//;p} }' | grep '^password=' | cut -d '"' -f2) retval=$? if [ $retval != 0 ]; then echo "get_ip error (exit code $retval)" >&2 exit $retval fi export POST_DATA="getpage=/usr/www/all/html/query.txt&login:command/password=$pw&var:cnt=1&var:n0=connection0:pppoe:status/ip" ip=$(echo -n "$POST_DATA" | REQUEST_METHOD="POST" REMOTE_ADDR="127.0.0.1" CONTENT_TYPE="application/x-www-form-urlencoded" CONTENT_LENGTH=${#POST_DATA} /usr/www/html/cgi-bin/webcm | sed -e '1,/^$/d;$d') retval=$? ;; -d|--dsld) ip=$(/sbin/showdsldstat | grep "0: ip" | cut -d\/ -f1 | cut -d ' ' -f3) retval=$? ;; -e|--extquery) ip=$(wget -q -O - http://checkip.dyndns.org | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+') retval=$? ;; -?|--help) helpmsg exit 0 ;; *) helpmsg >&2 exit 1 esac if [ $retval == 0 ]; then echo "$ip" exit 0 fi echo "get_ip error (exit code $retval)" >&2 exit $retval