#!/bin/bash
#send public ip address to e-mail
ping -c1 220.181.111.147 &>/dev/null #百度的IP
if [ $? -ne 0 ];then
echo "no connection"
exit 1
fi
for i in `seq 5`
do
ip=`curl "http://ifconfig.me/ip"`
if [ ${#ip} -lt 15 -a ${#ip} -gt 7 ];then
public_ip=$ip
break
else
public_ip="error"
fi
done
if [ ! $public_ip = "error" ];then
echo $public_ip|mutt -s "latest ip address" wzkiron@126.com
fi