Linux获取公网地址
- 服务器管理员获取服务器公网IP地址,若有变更邮件通知管理员
yum install -y mailx sendmail sendmail-cf
chkconfig sendmail on
service sendmail start
#!/bin/bash
Maill="xxxxxx@qq.com"
if [ ! -f "ipfile" ]; then
touch "ipfile"
echo > ipfile
fi
while [ true ]
do
new_ip=`curl members.3322.org/dyndns/getip`
old_ip=`cat ipfile`
if [ ! "$new_ip" = "$old_ip" ]; then
cat /dev/null > ipfile
echo $new_ip > ipfile
echo "外网 IP:"$new_ip",请妥善保管! " | mail -s '外网变更' $Maill
else
unset new_ip
unset old_ip
sleep 86400
fi
unset new_ip
unset old_ip
done