一个认证脚本
寝室在linux下上网老是断,需要重新认证才能上。于是觉得写个隔段时间自动根据网络状况重新认真的脚本。
1,准备工作,下载安装expect,需要tcl的支持。在debian和ubuntu下的软件包依赖关系处理很好
,直接以root运行apt-get install expect就可以了。
2,写认证的脚本,auth
---------------------------------
#!/usr/bin/expect
spawn xrgsu -d
expect "name:"
send "user\r"
expect "passowrd:"
send "passowrd\r"
expect "0):"
send "\r"
set timeout 7
expect "LogOff:"
---------------------------------
3,写检测网络并在网络不通时自动重新认证的脚本auth.py,用python实现
---------------------------------
#/usr/bin/python
from os import system
from time import sleep
state = 1
while True :
if state != 0 :
system("auth 1>/dev/null 2>/dev/null")
sleep(10)
state = system("ping 222.18.3.254 -w 3 1>/dev/null 2>/dev/null")
sleep(600)
---------------------------------
4,设置权限
#chmod +x auth
#chmod +x auth.py
5,运行
# auth.py &
OK,现在断网的时候会自动重新认证了