How to acquire your IP using a simple Script

Hello,

This entry should have been about Performance monitoring using Cacti, however due to my current workload I’m going to post a simple mini entry instead.

Sometimes you require the IP your machine is using to access the internet (the gateway’s internet IP), having a dynamic IP this task might end up being done periodically, a simple solution to that is this script, it wgets http://www.whatsmyip.net parses it and generates a file that has the IP, this can be later used with mailx or mutt to send the ip in an email, i’d have used twitter which i did before using their java API but recently they decided to change their API in a way that would make that impossible.

Update :

Found an entry on how to get twitter to work using the new OAuth scheme, its a rather complicated entry that i’m going to try to simplify and post here

 

http://benscomputer.no-ip.org/2010/Sep/prem_121905092010.shtml

 

 

########  ##     ## ########
##     ## ###   ###    ##
##     ## #### ####    ##
########  ## ### ##    ##
##     ## ##     ##    ##
##     ## ##     ##    ##
########  ##     ##    ##
## Script that Gets IP ##
#########################

ff=`date +%s`_date

mkdir /tmp/$ff

cd /tmp/$ff

wget -nv http://www.whatsmyip.net

cat index.html |grep “Your IP is:” >ip
sed  “s/<title>cmsGear powered website – Your IP is: //g”< ip >ipout

ip=`cut -d ‘<‘ -f -1 <ipout`

echo $ip>ipout

mv /tmp/$ff/ipout ~

rm -r /tmp/$ff

Advertisements

One thought on “How to acquire your IP using a simple Script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s