Author mekanik
originally posted on USALUG.org
Quote:
what IP address are you coming from? simply add this function to your ~/.bashrc dot-file and you can check your IP quickly from the shell without ever opening the browser...of course this won't take account for the use of any proxies...it will check to see if lynx or wget or links are installed on your workstation/server since some users may not have one or even any of them installed...if zero of the programs are installed, then the program will exit...if one of them exists, then it uses the one found by the precedence order of:
a) = lynx
b) = wget
c) = links
*note* an arguement of site1 or site2 will have to also be present or the script will exit...
Quote:
once you've sourced this file, added it to your ~/.bashrc dot-file or made it into a bash script, then all you have to do is run checkmyip [site1|site2]...
-mekanik
Code:
checkmyip() {
##
## @(#) checkmyip
##
## programmer: mekanik
## revision: 1.0.0 script/function development started
## date: 20050207
## description: check your IP address as the internet sees you.
##
## sites which we will check our ip address against. this can be expanded to more
## sites as you see fit. or modified as you see fit.
##
_site1="http://www.whatismyip.com/"
_site2="http://www.networksecuritytoolkit.org/nst/cgi-bin/ip.cgi"
## programs listed in order of preference which we are going to set to the program
## used to extract the data pending the retval used in the below check.
##
_lynx="`which lynx 2>/dev/null`"
_wget="`which wget 2>/dev/null`"
_links="`which links 2>/dev/null`"
## lets check to see if any of the programs are present on our system, if they exist and the
## site was 'site1' or 'site2', then get our IP, else exit out and inform the user to install
## one of the programs...
##
if [ $# != 1 ];then
printf "please use [site1] or [site2], exiting\n"
elif [ $# = 1 ] && [ X"$1" = X"site1" ];then
if [ -e "$_lynx" -a -x "$_lynx" ];then
_prog="$_lynx"
elif [ -e "$_wget" -a -x "$_wget" ];then
_prog="$_wget"
elif [ -e "$_links" -a -x "$_links" ];then
_prog="$_links"
elif [ ! -e "$_lynx" -o ! -e "$_wget" -o ! -e "$_links" ];then
printf "none of the programs exist, please install 'lynx', 'wget', or 'links'. exiting\n"
fi
if [ X"${_prog##/*/}" = X"lynx" ];then
$_prog -dump "$_site1" | awk '/Your IP/{print $4}'
elif [ X"${_prog##/*/}" = X"wget" ];then
$_prog -q "$_site1" -O /dev/stdout | awk '/Your IP/{print $4}'
elif [ X"${_prog##/*/}" = X"links" ];then
$_prog -dump "$_site1" | awk '/Your IP/{print $4}'
fi
elif [ $# = 1 ] && [ X"$1" = X"site2" ];then
if [ -e "$_lynx" -a -x "$_lynx" ];then
_prog="$_lynx"
elif [ -e "$_wget" -a -x "$_wget" ];then
_prog="$_wget"
elif [ -e "$_links" -a -x "$_links" ];then
_prog="$_links"
elif [ ! -x "$_lynx" -o ! -x "$_wget" -o ! -x "$_links" ];then
printf "none of the programs exist, please install 'lynx', 'wget', or 'links'. exiting\n"
fi
if [ X"${_prog##/*/}" = X"lynx" ];then
$_prog -dump "$_site2"
elif [ X"${_prog##/*/}" = X"wget" ];then
$_prog -q "$_site2" -O /dev/stdout
elif [ X"${_prog##/*/}" = X"links" ];then
$_prog -dump "$_site2"
fi
fi
}