LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 6940|回复: 10

适用于ADSL的连接脚本。

[复制链接]
发表于 2004-2-11 23:57:44 | 显示全部楼层 |阅读模式
我感到抱歉,脚本有点问题,现在我已经改过,请用现在的脚本。。。。
Date: Thu Feb 12 19:44:10 CST 2004
这脚本只适用与动态的IP联网。。


  1. #!/bin/bash
  2. #Author:home
  3. #Date : Thu Feb 12 16:25:59 CST 2004
  4. #System : RedHat 9.0
  5. if [ $# -gt 5 ] ; then
  6.         echo " error command,pleas look at /forum/src/reup "
  7.         exit 0
  8. fi
  9. echo "waiting about 12 second...."
  10. IP=`ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"`
  11. MAC=`ifconfig eth0|grep eth0|awk '{print $5}'`
  12. echo "             $IP"
  13. echo "The old IP is  $MAC"
  14. sleep 7
  15. adsl-stop
  16. #down

  17. #up
  18. if [ $# == 0 ] ;then
  19.             echo "The MAC has not changed !"
  20. else
  21.             if [ $# == 1 ] ;then
  22.                      ifconfig eth0 down
  23.                      ifconfig eth0 hw ether 00:e0:"$1":a3:e3:d8
  24.                      ifconfig eth0 up
  25.             elif [ $# == 2 ] ;then
  26.                      ifconfig eth0 down
  27.                      ifconfig eth0 hw ether 00:e0:"$2":a3:"$1":d8
  28.                      ifconfig eth0 up
  29.             elif [ $# == 3 ] ; then
  30.                      ifconfig eth0 down
  31.                      ifconfig eth0 hw ether 00:e0:e0:"$1":"$2":"$3"
  32.                      ifconfig eth0 up
  33.             elif [ $# == 4 ] ; then
  34.                      ifconfig eth0 down
  35.                      ifconfig eht0 hw ether 00:e0:"$1":"$2":"$3":"$4"
  36.                      ifconfig eth0 up
  37.             elif [ $# == 5 ] ; then
  38.                      ifconfig eth0 down
  39.                      ifconfig eht0 hw ether 00:"$5":"$1":"$2":"$4":"$3"
  40.                      ifconfig eth0 up
  41.             else echo "unknown error" ; exit 0
  42.             fi
  43.             NEWMAC=`ifconfig eth0|grep eth0|awk '{print $5}'`
  44.             echo "The new MAC is $NEWMAC"
  45. fi
  46. adsl-start
  47. NEWIP=`ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"`
  48. while [ "$NEWIP" == "$IP" ] ; do
  49.          adsl-stop;echo "waiting about 8 second  ... " ;sleep 5;adsl-start
  50.          NEWIP=`ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"`
  51. done
  52. echo "Now the IP is  $NEWIP "
复制代码


发表于 2004-2-12 00:04:02 | 显示全部楼层
我记得home兄写了不少adsl的脚本啦~,正好明天我要安adsl了,可以试一试喽~~ :thank
 楼主| 发表于 2004-2-12 00:07:55 | 显示全部楼层
以前写过一个,大家有什么意见和建议吗?请提出来,还可以扩充一下功能。。
发表于 2004-2-12 00:20:21 | 显示全部楼层
我想如果ifconfig要用ip来代替的话,也许能精简些~~,;)
/sbin/ip addr|awk '/peer/{print $2}'
比用ifconfig要简炼点吧~
 楼主| 发表于 2004-2-12 19:42:41 | 显示全部楼层
我感到抱歉,上面的脚本有点问题,现在我已经改过,请用现在的脚本。。。。

斑竹的注意不错,可以改改的。。
发表于 2004-2-12 20:30:03 | 显示全部楼层
我用adsl-setup设置,用adsl-start和adsl-stop来启动/停止,;)
btw:ip的用法实在要比ifconfig功能多得多;)
发表于 2004-2-12 22:18:58 | 显示全部楼层
ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"

这句话好象有点问题,我执行的结果第一行有字符“Link",第二行是IP地址。这句怎么样:
#ifconfig eth0 | sed -n 's/^.*addr:\([0-9.]*\).*$/\1/p'
发表于 2004-2-12 22:57:21 | 显示全部楼层
每个系统都不同,要看情况,贴出的的ifconfig 看看.
发表于 2004-2-13 00:26:43 | 显示全部楼层
最初由 7dehao 发表
ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"

这句话好象有点问题,我执行的结果第一行有字符“Link",第二行是IP地址。这句怎么样:
#ifconfig eth0 | sed -n 's/^.*addr:\([0-9.]*\).*$/\1/p'

:ask,这样的结果是什么? 我测试后什么都没有呀~~,另外,一般取IP地址都用ppp来作为关键字~,用eth0还是....最好把你的ifconfig的结果贴出来 .
发表于 2004-2-13 12:08:25 | 显示全部楼层
最初由 javalee 发表
:ask,这样的结果是什么? 我测试后什么都没有呀~~,另外,一般取IP地址都用ppp来作为关键字~,用eth0还是....最好把你的ifconfig的结果贴出来 .

我是在路由器后面上adsl的,ifconfig -a 没有ppp0,所以测试的时候就用eth0了,如果是直接接adsl的话可以把eth0换成ppp0,应该没什么问题.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表