Wednesday, September 16, 2015

OpenWRT hange after enable wifi -- wireless interface

I have install openwrt on mikrotik rb951ui-2hnd, and when enable the wireless interface the router start to hang. Reboot the router, we can connect to the router around 5-7 seconds, then the connection will lose again.

So I create a script to disable the wireless interface and it save the router after the wireless is diabled

************ the script***************

import pexpect
import subprocess
from subprocess import PIPE
import re

cont = False
routerpassword = "mypassword"

routerip = '192.168.1.1'
while cont != True:

    t = subprocess.Popen(["ping","-W", "1", "-c", "1", routerip],stdout=PIPE)
    stdout = t.communicate()

    for i in stdout:
        if i =="" or i == None:
            continue
        if re.search("1 received", i):
            print "reach"
            cont = True
        else:
            print "no reach"

child = pexpect.spawn('ssh root@'+routerip)
child.expect('assword')
child.sendline(routerpassword)
child.expect('#')

child.sendline('uci set wireless.@wifi-device\[0\].disabled=1; uci commit wireless; wifi')
child.expect('#')
child.sendline("ifconfig")
child.expect('#')
child.sendline("exit")

print child.before   # Print the result of the ls command.
child.interact() 


***********************************************

the script required pexpect to install  and change the ip and password. rim it, when the router is restarted, it will ping the router, after the router reply it will remote the router to disable the wireless interface

No comments:

Post a Comment