Re: what is my IP?
On Sat, 2005-01-29 at 16:35 +0100, gerhard wrote:
> Am Samstag 29 Januar 2005 15:31 schrieb Gerhard Gaußling:
> > $ su --command="ifconfig |egrep -A1 Point-to-Point|egrep '(inet
> > addr:)'| sed -n '1p'"|gawk '{print $2}'|cut -c6-22
> better You use this script, it doesn't need root access:
> #/usr/local/bin/myip
> #!/bin/bash
> echo "Current IP is:"
> /sbin/ifconfig |egrep -A1 Point-to-Point|egrep '(inet addr:)'| \
> sed -n '1p'|gawk '{print $2}'|cut -c6-22
>
> Kind regards
>
> Gerhard Gaußling
>
Another one-liner using ifconfig (where ethx is your external network
interface):
$ /sbin/ifconfig ethx | grep inet | awk '{print $2}' | awk -F : '{print
$2}'
Here is an OVERKILL script for checking your IP address--there are many
ways to check your IP address
(requires package curl):
#!/bin/bash
# Script to upload encrypted IP address to web page.
# Created by Douglas Ward
# 2004-July-07
# 2004-November-13 - if checkip.dyndns.org returns nothing, retry 6
times
#
# Capture IP from IFACE -> ip
# Check for new address. If not new, exit script.
# If new, continue and log new address.
# uses checkip.dyndns.org AND curl
# retry checkip 6 times, if needed, fail without writing to log
# backup to checking ifconfig
# edited for debian-user 2005 Jan 30
#
# Use ifconfig; use in case of web check failure? YES or NO
IFCFG="YES"
IFCFG_BAK="YES"
# Use web check in case mysteriously ifconfig fails? YES or NO
DYN_BAK="YES"
IFACE="eth0"
# [writable] Directory to hold logs
DIR=.
PATH=${DIR}/:/bin:/sbin:/usr/bin
if [ ! -r ${DIR}/ip ]; then
touch ${DIR}/ip
echo 0 > ${DIR}/ip
fi
if [ ! -r ${DIR}/log ]; then
touch ${DIR}/log
fi
IPOLD=$(cat ${DIR}/ip)
if [ $IFCFG = "YES" ]; then
IPNEW=$(/sbin/ifconfig $IFACE | grep inet | awk '{print $2}' | awk
-F : '{print $2}')
echo $IPNEW
while [ ! $IPNEW ]; do
sleep 90
IPNEW=$(/sbin/ifconfig $IFACE | grep inet | awk '{print $2}' |
awk -F : '{print$2}')
if [ $DYN_BAK = "YES" ]; then
if [ ! $IPNEW ]; then
IPNEW=$(curl http://checkip.dyndns.org/ 2>/dev/null |
grep "Current" | aw//')print $6}' | sed 's/<\/body><\/html>//' | sed 's/
fi
fi
COUNT=$COUNT+1
if [ $COUNT = 6 ]; then
exit
fi
done
fi
if [ $IFCFG = "NO" ]; then
IPNEW=$(curl http://checkip.dyndns.org/ 2>/dev/null | grep "Current"
| awk '{print $6//') sed 's/<\/body><\/html>//' | sed 's/
echo $IPNEW
while [ ! $IPNEW ]; do
sleep 90
IPNEW=$(curl http://checkip.dyndns.org/ 2>/dev/null | grep
"Current" | awk '{prin//')}' | sed 's/<\/body><\/html>//' | sed 's/
if [ $IFCFG_BAK = "YES" ]; then
if [ ! $IPNEW ]; then
IPNEW=$(/sbin/ifconfig $IFACE | grep inet | awk '{print $2}'
| awk -F : '{print $2}')
fi
fi
COUNT=$COUNT+1
if [ $COUNT = 6 ]; then
exit
fi
done
fi
echo "Current IP Address:"
echo $IPNEW
if [ $IPOLD = $IPNEW ]; then
exit
fi
rm ${DIR}/ip*
# Logging information in this string
IPLOG=$(echo $(date) $IPNEW)
echo IP Address change
echo $IPNEW > ${DIR}/ip
echo $IPLOG >> ${DIR}log
# mail logging string to root
echo -e New Address:\\n$IPLOG\\n\\nAddress Log:\\n$(cat /etc/postip/log)
| mail root -s"router IP ADDRESS CHANGE"
# END OF SCRIPT
Reply to: