# A script to auto open wlan using telnet on zyxel p880importtelnetlibimporttimedefread_until(tn,string):ifstringintn.read_until(string,1):returnelse:raiseException()while(True):try:tn=telnetlib.Telnet("192.168.1.1")read_until(tn,"Login: ")tn.write("cht\n")# usernameread_until(tn,"Password: ")tn.write("chtsvdsl\n")# passwordread_until(tn,"2. LAN/WLAN")tn.write("2\n")# LAN/WLANwhile(True):time.sleep(5)read_until(tn,"4. Show WLAN")tn.write("4\n")# Current statusexpect=tn.expect(["Disabled","Enabled"],1)[0]ifexpect==1:# If wlan is enabledtn.write("\n")print"Stay Enabled"continueifexpect==-1:raiseException()print"Disabled -> Enabled"tn.write("\n")read_until(tn,"3. Configure WLAN")tn.write("3\n")# Configure WLANread_until(tn,"[0-no, 1-yes]")tn.write("1\n")# yesread_until(tn,"Hit <enter> to continue")tn.write("\n")except:print"error"tn.close()continue
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.