Register
It is currently Sat Aug 30, 2014 12:21 am

checkmyip - get the IP address that the Internet sees you us


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Tue May 17, 2005 8:10 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 666
Location: Des Moines, Iowa
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
}


Top
 Profile WWW  
 PostPosted: Sat Sep 02, 2006 9:40 pm   

Joined: Sat Sep 02, 2006 9:26 pm
Posts: 4
Location: Baltic, South Dakota
Why wouldn't you just do something like this instead? Being since this is geared for logging and gaining access to a shell anyways.

Quote:
#!/bin/bash
typeset -R IFCONFIG="/sbin/ifconfig"
typeset -R CUT="/usr/bin/cut"
typeset -R GREP="/bin/grep"
typeset -R AWK="/usr/bin/awk"

typeset -R NIC="eth0"

${IFCONFIG} ${NIC} | ${GREP} -m 1 inet | ${AWK} '{print $2}' | ${CUT} -d: -f2


Top
 Profile WWW  
 PostPosted: Sun Sep 03, 2006 8:38 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
well iccus... if the user is like me... i have a local Ip address assigned to my NIC (which is what you would pull up using that code).


Top
 Profile  
 PostPosted: Sun Nov 18, 2007 9:09 am   

Joined: Sun Nov 18, 2007 8:28 am
Posts: 6
I have a simple program that emails me when my ip changes:

Code:
#!/bin/sh

EMAIL=mycoolemailaddress@mail.org
FILE=/var/local/ipdata

NEWIP=`wget -q -O - http://mywebsite.com/yourip.pl` && OLDIP=`cat $FILE`

if [ "$NEWIP" != "$OLDIP" ]; then
echo "New IP: $NEWIP" | mail -s "IP Changed" $EMAIL
echo $NEWIP > $FILE
echo "Notified by email ($EMAIL)"
fi


The perl script yourip.pl is simply:
Code:
#!/usr/bin/perl
  print "Content-Type: text/plain\r\n\r\n$ENV{REMOTE_ADDR}";


Top
 Profile WWW  
 PostPosted: Tue Apr 01, 2008 10:28 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
whatismyip.com wrote:
Some automators are hitting our home page really hard eating up a lot of bandwidth and possibly causing the site to be slow for other visitors. So we've created an automation page.


With that in mind, this is what I use.

Code:
lynx -dump 'http://whatismyip.com/automation/n09230945.asp' | awk '{ print $1 }'


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP