LinuxSir.cn,穿越时空的Linuxsir!

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

ADSL上网脚本

[复制链接]
发表于 2003-12-26 14:18:19 | 显示全部楼层 |阅读模式
#cat up
#!/bin/bash
MAC=`ifconfig eth0|grep eth0|awk '{print $5}'` #这个得到当前的MAC地址。
if [ $# == 0 ] ;then echo "The MAC have not changed !" ;echo "Now the MAC is $MAC "#如果没有参数,只输入脚本名就选择这里。
elif [ $# == 2 ] ;then #这里在命令有跟着两个参数,这里是你指定的MAC最后两个域。如这个脚本叫做up,  那么输入up a8 d9 ,注意MAC是以十六进制表示的,字母不要输入比F大的。
echo "The old MAC is $MAC"
ifconfig eth0 down  #使网卡注销出系统。
ifconfig eth0 hw ether 00:**:**:**:"$1":"$2" #设置MAC,这里的$1表示第一个参数,$2表示第二个参数。
ifconfig eth0 up #重新激活网卡。
NEWMAC=`ifconfig eth0|grep eth0|awk '{print $5}'`
echo "The new MAC is  $NEWMAC"
else echo "command error " ;exit 0 #结束这个进程。
fi ;echo "lease wait......"
adsl-start ;sync;NEWIP=`ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"` #这里的sync是刷新缓冲区。不要也行。#连网,后打印出IP地址。
echo "Now the IP is $NEWIP "
fi



还有个断开连接的脚本:
# cat down
#!/bin/bash
ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"
ifconfig eth0|grep eth0|awk '{print $5}'
adsl-stop


不知道为什么输入两个参数不行(这两个参数用于改变MAC,具体请看脚本):ask
是用ADSL上网,这是ifconfig
eth0      Link encap:Ethernet  HWaddr 00:**:**:**:**:**
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:507 errors:0 dropped:0 overruns:0 frame:0
          TX packets:488 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:333786 (325.9 Kb)  TX bytes:115596 (112.8 Kb)
          Interrupt:11 Base address:0xe000

lo        Link encapocal Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:86 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5068 (4.9 Kb)  TX bytes:5068 (4.9 Kb)

ppp0      Link encapoint-to-Point Protocol
          inet addr:220.*.*.*  P-t-P:172.0.0.1  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
          RX packets:458 errors:0 dropped:0 overruns:0 frame:0
          TX packets:439 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:320699 (313.1 Kb)  TX bytes:102938 (100.5 Kb)


发表于 2003-12-26 15:36:42 | 显示全部楼层
估计又是引号的错!手动没问题吧~
 楼主| 发表于 2003-12-26 15:44:53 | 显示全部楼层
直接输入adsl-start没问题。这是下网再连上的情况。
# up d8 a9
The old MAC : 00:E0:**:**:**:A0
/root/bin/up: line 13: 00:**:**:**:d8:a9: command not found
The new MAC :
/root/bin/up: line 15: *.*.*.*: command not found
now IP is

这时已连上了,就是新的MAC和IP没有显示。
发表于 2003-12-26 18:21:21 | 显示全部楼层
NEWMAC= `ifconfig eth0|grep eth0|awk '{print $5}'`
注意等号后面的空格!
adsl-start ;sync; sleep 3; NEWIP= `ifconfig ppp0|grep addr|awk '{print $2}'|cut -f2 -d ":"`
这行也是!
都去掉!
 楼主| 发表于 2003-12-26 19:29:14 | 显示全部楼层
:thank :thank 以后要注意格式了。


不知道解释得好吗?要是不满意,请帮我改改!!!!
发表于 2003-12-26 19:59:25 | 显示全部楼层
最初由 home 发表
:thank :thank 以后要注意格式了。

麻烦home兄把脚本加些注释,整理整理.用adsl上网的脚本很有代表性,贴到[脚本欣赏区],让兄弟们都学习学习~~,:thank
发表于 2009-2-19 21:32:19 | 显示全部楼层
37531679  请加入 linux 讨论群
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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