远程操作局域网中的主机

我想把办公室的开发机通过映射实现在家远程访问。由于动态ip可能重启后变化,让linux自动发微博或者email通知我。
获取广域网的方法:

curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
curl -s http://www.3322.org/dyndns/getip 这个也行

采用定时发不是很科学。所以还需要设置触发条件,我希望的是在重启了路由器的时候发送,这种情况的表现是——会断网。
能否判断网络重新连接后触发,另一种情况是可能会断电,节假日关机等情况。我希望是开机后马上触发。先有个思路,后面看怎么做。

-----------------------------------------------------------------------------------

补充:
刚学shell,用shell写了个发送微博的脚本

#! /bin/sh
username=您的sina微博账号
password=您的密码
app_key=sina应用的app_key
realip=`curl -s http://www.3322.org/dyndns/getip`
nowtime=`date`
curl -u $username:$password -d "source=$app_key&status=$realip $nowtime" https://api.weibo.com/2/statuses/update.json

结果如下:

为了简便ip不发生变化时候不需要发送微博,修改脚本如下:

#! /bin/sh
username=用户名
password=密码
app_key=APP KEY
realip=`curl -s http://www.3322.org/dyndns/getip`
previp=`cat ip.txt`

if [ $previp != $realip ]; then
        echo $realip > ip.txt
        nowtime=`date`
        curl -u $username:$password -d "source=$app_key&status=$realip $nowtime" https://api.weibo.com/2/statuses/update.json
fi

然后只需要设置成定时发送就行了。

原文地址:https://www.cnblogs.com/ikodota/p/2834576.html