在Linux实现基于动态IP的WWW服务器
基于动态ip的服务器同样可以开设www服务接受客户端的访问,这可以通过以下的脚本来实现.请先建立ppp连接,配置好httpd,测试它可以工作.
建立如下的脚本程序:
* web_up: 上载网页的脚本.
* web_down: 断开连接的脚本.
* update_uppage: perl 脚本创建包含更新ip地址的html页面.
* up.html_source; 固定部分的页面.
* down.html: 连接断开时使用的页面.
* /etc/add, /etc/last_add: 存放ip地址的文件.
* ip-down, ip-up: ppp连接断开和连接时拒绝上载的文件.
scripts web_up:
#!/bin/sh
#check new ip
new_ip()
{
if [ -f /etc/add ] ; then
if [ -f /etc/last-add ] ; then
if /usr/bin/diff /etc/add /etc/last_add >/dev/null ; then
exit 1
else
return 0
fi
else
return 0
fi
else
exit 1
fi
}
#check whether maroon is connected
try_connect()
{
if ping -c4 -13 128.101.118.21 2>& | grep "0 packets" > /dev/null
then
return 1
else
return 0
fi
fi
}
if try_connect
then
touch /var/run/maroon_connected
else
rm -f /var/run/maroon_connected
fi
# ftp to update page
if [ -f /var/run/maroon_connected ] && new_ip
then
# update_uppage is perl scripts, exit status is opposite of shell(文章来源 www.iocblog.net)
if ( ! /home/honglu/public_html/update_uppage )
then
cd /home/honglu/public_html
if echo "put up.html /nlhome/m508/luxxx012/dynamic.html" | /usr/bin/ftp maroon
then
rm -f /etc/last_add
cp /etc/add /etc/last_add
exit 0
else
exit 1
fi
fi
else
exit 1
fi
scripts web_down
# ftp to send down.html page
if [ -f /var/run/maroon_connected ]
then
cd /home/honglu/public_html
if echo "put down.html /nlhome/m508/luxxx012/dynamic.html" | /usr/bin/ftp maroon
then
rm -f /etc/last_add
else
exit 1
fi
else
exit 1
fi
执行如下脚本:
#!/bin/sh
if web_down
then
shutdown -h now
else
echo "can not web_down"
exit 1
fi
Tag: 动态IP
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。