路由器上 /etc/storage/ddns.sh
#!/bin/bash
newip=`ifconfig ppp0|grep inet|awk '{print $2}'|awk -F ':' '{print $2}'`
echo $ip > temp
oldip=`cat temp`
if [ "$oldip" == "$ip" ];then
echo "Same IP"
else
curl http://andi.press/ebook/ddns.php?ip=$newip:10090
fi
chmod +x /etc/storage/ddns.sh
crontab -e
0 * * * * /etc/storage/ddns.sh
服务器上 ddns.php
<?php
header("Content-type:text/html;charset=utf-8");
$ip = $_GET['ip'];
$host = '';
$port = '3306';
$user = '';
$password = '';
$database = '';
$con = mysql_connect($host.':'.$port,$user,$password);
mysql_query("SET NAMES 'UTF8'");
mysql_select_db($database,$con);
$query = "truncate ip";
$result = mysql_query($query,$con);
$query = "insert into ip(addr) values(\"".$ip."\")";
$result = mysql_query($query,$con);
if ($result)
echo "ip:".$ip." status:OK";
else
echo "ip:".$ip." status:Failed";
mysql_free_result($result);
mysql_close($con);
?>