Skip to content

Instantly share code, notes, and snippets.

@Revolution1
Last active February 8, 2017 16:06
Show Gist options
  • Save Revolution1/6788620 to your computer and use it in GitHub Desktop.
Save Revolution1/6788620 to your computer and use it in GitHub Desktop.
lua的openwrt拨号脚本,用于四川电信校园网
#!/usr/bin/env lua
function md5sum(str)
local command="echo -n "..str.." | md5sum"
local f=io.popen(command)
local out=f:read('*all')
return out:sub(1,-5)
--f:close()
end
--print(md5sum("asdf")) -- 912ec803b2ce49e4a541068d495ab570
--START HERE
function get_account(username,password)
local ver="Tyroth"
local temp=string.format("%X",os.time())
username=string.upper(username)
local s=temp..ver..username..password
local m=string.upper(md5sum(s))
m=string.sub(m,1,20)
local encodedaccont="~ghca"..temp.."2002"..m..username
return encodedaccont
end
--print(get_account(arg[1],arg[2]))
function get_account_v07(username,password)
--the encrypt algorithm version 07
--For backup
local ver="jepyid"
local temp=string.format("%X",os.time())
username=string.upper(username)
local s=ver..username..temp..password
local m=string.upper(md5sum(s))
m=string.sub(m,1,20)
local encodedaccont="~ghca"..temp.."2007"..m..username
return encodedaccont
end
function pppoe_dial(username,password)
--restore network config file
local restore="if [ ! -f /etc/config/network ];then cp /root/network.bak /etc/config/network;fi"
os.execute(restore)
print("Dialing...")
--print(username)
local setuser="uci set network.wan.username="..get_account_v07(username,password)
local setpass="uci set network.wan.password="..password
os.execute(setuser)
os.execute(setpass)
os.execute("uci commit")
os.execute("/etc/init.d/network restart")
os.execute("logread|grep pppd |tail -n 20 >/root/ppplog")
--local pppd="pppd plugin rp-pppoe.so mtu 1492 mru 1492"
--if not io.open("/etc/crontabs/root") then
--cron--
os.execute("killall -9 crond")
--local mycron="flag=0;for ip in 126.com 163.com qq.com; do if ping -c 1 $ip | grep 'ttl' >/dev/null;then flag=1; break;fi; done; if [ $flag -eq 0 ] ;then STRD "..username.." "..password.." >/dev/null;fi;"
local mycron="*/1 * * * * flag=0;for ip in 126.com 163.com qq.com; do if ping -c 1 $ip | grep 'ttl' >/dev/null;then flag=1; break;fi; done; if [ $flag -eq 0 ] ;then sh /etc/rc.local >/dev/null;else cp -f /etc/config/network /root/network.bak;fi; 2>/dev/null"
--local setcron="*/1 * * * * "..mycron.." 2>/dev/null"
crontab=io.open("/etc/crontabs/root","w")
crontab:write(mycron)
crontab:close()
local startcron="crond -c /etc/crontabs"
os.execute(startcron)
--end
print("Done!")
end
--main--
if arg[1] and arg[2] then
pppoe_dial(arg[1],arg[2])
else
print("USAGE:\n "..arg[0].." USERNAME PASSWORD\n")
end
os.exit(0)
--end main--
@JONYHY
Copy link

JONYHY commented Oct 20, 2016

学长你好 我看了你的教程 我是成都理工的 开机计划都设置了 但是wan口怎么设置啊

@JONYHY
Copy link

JONYHY commented Oct 20, 2016

我的邮箱352144278@qq.com 希望学长有空的话指点一下 我的路由器是hg255d刷好了openwrt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment