软讯网络 > 操作系统 > 其他操作系统 > ADSL动态地址的获取
【标 题】:ADSL动态地址的获取
【关键字】:
ADSL
【来 源】:http://blog.chinaunix.net/article.php?articleId=63879&blogId=9978
ADSL动态地址的获取

如何获取ADSL的动态地址
这是一个获得动态IP地址的脚本。在FreeBSD中测试成功。
其中dip.sh是获取tun0上绑定的地址的脚本,而ftpfile.sh是将地址传到FTP服务器上。
++++++++++++++++++++dip.sh++++++++++++++++++
#!/bin/sh
gw_ipaddr="192.168.0.1"
while true ;do
sleep 150
cgw_ipaddr=$(ifconfig tun0|grep inet|cut -d ' ' -f 2)
if [ "$gw_ipaddr" = "$cgw_ipaddr" ]; then
sleep 150
else
set gw_ipaddr
gw_ipaddr="$cgw_ipaddr"
ctime=$(date "+%Y/%m/%d %H:%M:%S")
echo GW IPaddr[$ctime] : $gw_ipaddr .>>./tmpdata
./ftpfile.sh
rm tmpdata
fi
done
+++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++ftpfile.sh++++++++++++++++
#!/bin/sh
ftp -n << !
open FTPServerIP
user USERNAME PASASWD
binary
prompt off
put ./tmpdata gwIP.txt
close
bye
!
+++++++++++++++++++++++++++++++++++++++++