Due to work needs, wrote a automatic check the office area wireless AP is dropped line Python script, I use the PYTHON3 environment, please note
Also note is that I use Ruijie's wireless AC and wireless APs. Other brands only need to replace the command content in the script content to change to your brand wireless AC command.
Here is the actual script content:
#!/usr/local/python3/bin/python3 Import telnetlib,time,osdef do_telnet (host,password,finish,commands): Import Telnetlib tn = telnetlib. Telnet (Host, port=23) tn.read_until (b ' Password: ') tn.write (Password + b ' \ n ') tn.read_until (finish) Tn.write (CO MMANDS1 + b ' \ r \ n ') time.sleep (1) tn.read_until (b ' Password: ') tn.write (Password + b ' \ n ') time.sleep (1) tn.re Ad_until (b ' # ') tn.write (commands + B ' \ n ') Time.sleep (10) # It must wait for 10 seconds, because you will wait a long time after you write the command. Tn.write (b ' exit\n ') result = Tn.read_all () file_object = open ('/opt/scripts/network/result.txt ', ' WB ') FILE_OBJEC T.write (Result) file_object.close () tn.close () if __name__ = = ' __main__ ': Host = ' 192.168.1.12 ' # telnet Server IP Password = ' abc123 '. Encode (encoding= ' utf-8 ') # login password finish = ' > '. Encode (encoding= ' utf-8 ') # command Prompt commands = ' s How Web-api ibeacon '. Encode (encoding= ' utf-8 ') commands1 = ' en '. Encode (encoding= ' utf-8 ') do_telnet (Host,password,fini Sh,commands) #判断AP是否在线with Open ('/opt/scripts/network/result.txt ', ' R ') as F:for i in F:if ' code ' in I: #把 [email protecte D] Replace empty and convert to dictionary i = eval (i.replace (' ac#exit ', ')) Aplist = i[' data '] [' list '] day = Time.str Ftime ('%y-%m-%d ', Time.localtime ()) time = Time.strftime ('%h:%m:%s ', Time.localtime ()) for J in Apli St:if j[' status ']! = ' run ': IP = j[' IP '] mac = j[' Mac '] name = j[' name '] status = j[' status '] with open (' Satus.txt ', ' a ') as F1: Message = ' Current time: ' + day + ' + ' + ', ' + ' IP for wireless APs: ' + IP + ', ' + ' current status is not online, ' + ' MAC address of wireless AP: ' + mac + ', ' + ' wireless AP name is: ' + name + ', ' + ' wireless AP Status: Not Online ' f1.write (message + ' \ n ') #发 Send Alarm Os.system ('./weixin.py a ABC wireless AP name:%s Not in line, please check! '%name) else:print (' Wireless AP status OK! ')
Monitor if wireless APs are online python scripts