0 Replies - 1432 Views - Last Post: 12 July 2007 - 05:12 PM

#1 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6560
  • View blog
  • Posts: 30,699
  • Joined: 10-May 07

Resolve & Display Your Ip Address

Posted 12 July 2007 - 05:12 PM

Description: You must have root level permissions to run the script (it accesses ifconfig)Show your ip, compares it to what it may have used to be.
#!/bin/sh

[email protected]
tmp_file=/tmp/.myip

whoami=`whoami`
if [[ ${whoami} != 'root' ]]
then
  echo "You must be root to run this program"
  exit 0
fi
## have to get old ip 1st
if [[ -f ${tmp_file} ]]
then
  myip=`cat ${tmp_file}`
  oldip=`cat ${tmp_file}`
else
  touch ${tmp_file}
  newrun=1
fi

## Dialup users:
/sbin/ifconfig | 
sed -n -e '/ppp0|ppp1|ppp2|ppp3/,/$$/!d' -e 
's/.*addr:([0-9]+.[0-9]+.[0-9]+.[0-9]+).*/1/p' > ${tmp_file}

## Lan users:
/sbin/ifconfig | 
sed -n -e '/eth0|eth1/,/$$/!d' -e 
's/.*addr:([0-9]+.[0-9]+.[0-9]+.[0-9]+).*/1/p' > ${tmp_file}

## Remove loopback:
cat ${tmp_file} | sed -e 's/127.0.0.1//p' > ${tmp_file}

myip=`cat ${tmp_file}`

test "$myip" = "$oldip"
#echo $?
#echo $myip
if [ $? -eq 1 ]; then
## Uncomment the following line if you wish to have the alert e-mailed to you.
#  mail $addy -s Alert: ip has changed -f Your ip has expired.  New ip is $myip
  if [ $newrun -eq 1 ]; then
    echo Setting up ip for the 1st time.
    echo New ip is $myip
  else
    echo Alert: ip has changed!
    echo New ip is $myip
  fi
  else echo ip remains $myip
fi



Is This A Good Question/Topic? 0
  • +

Page 1 of 1