Monitor whether wireless APs are online python scripts

Source: Internet
Author: User
Tags python script

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.