Pinger SMS Alert Python script

Source: Internet
Author: User
Tags python script

#!/usr/bin/Env python#-*-coding:utf-8-*-Import Urllibimport urllib2mobile= [18688965555,] #mobile= [15013805555,] #CONTENT= u'Customer'def SMS (CONTENT): forIinchMobile:url='http://219.33.33.33/GsmsHttp'parms= {                'username':'73333:admin',                'Password':'61029000',                ' from':'3399',                ' to': I,'content': CONTENT,'Presendtime':"',                'Expandprefix':'113'} querystring=Urllib.urlencode (parms) print (querystring) U= Urllib2.urlopen (url+'?'+querystring) Print (U) import subprocessimport collectionsimport sysreload (SYS) sys.setdefaultencoding ('GBK') def ping2 (): DiC=collections. Ordereddict () #dic [u'Google room'] ='8.8.8.8'Dic[u'Quanzhou Mobile'] ='4.2.2.2'Lines=list (dic.values ()) Keys=list (Dic.keys ()) forLineinchLines:line=Str (line) line=Line.strip () ping=subprocess. Popen (["Ping","- C"," -","- W","1", line], stdout=subprocess. PIPE, stderr=subprocess. PIPE) out, error =ping.communicate () print outNum=int( out. Split ("%")[0].split (",")[-1])        ifNum> -and num< -: SMS (U'{0} network exception, packet drop rate: {1}%'. Format (Keys[lines.index (line), num)) elif num== -: SMS (U'{0} network outage'. Format (Keys[lines.index (line))) Print errorif__name__ = ='__main__': Ping2 ()

The above SMS alert, as long as your SMS HTTP interface and account matching, this is a complete script. Python is in version 2.0.

Pinger SMS Alert Python script

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.