#!/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