您好,登录后才能下订单哦!
今天就跟大家聊聊有关python 使用Twilio免费短信网关报警方法是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
二、写python 接口
sms.py
点击(此处)折叠或打开
#coding: utf-8
from twilio.rest import Client
def sms(t):
				    account_sid = " "
				    auth_token = " "
				    client = Client(account_sid, auth_token)
				    message = client.messages.create(
				        to="= ",#自己的手要号码 
				        from_=" ",#在网站上申请的手机码,只能用这个号码发信息
				        body=t.decode("utf-8"))#编码密码使用utf-8才发送中文。
print(message.sid)
引用sms模块
点击(此处)折叠或打开
#!/usr/bin/python
import socket
import time
from sms import sms
import logging
import time
def port_try(host,port):
				    shijian=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
				    sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
				    sk.settimeout(1)
				    try:
				        sk.connect((host,port))
				        t=host+"服务器 "+str(port)+" 连接正常 "+str(shijian)
				        #sms(t)
				        print t
				    except Exception:
				        w=host+" 服务器 "+str(port)+" 无法连接 "+str(shijian)
				        print w
				        sms(w)
				    sk.close()
				file = open("/root/script/ip.txt")#ip地址写法192.16.0.1:80
while True:
				    line = file.readline().strip('\n')
				    if len(line)==0:break
				    ip=str(line.split(':',1)[0])
				    port=int(line.split(':',1)[1])
				    port_try(ip,port)
#time.sleep(2)
看完上述内容,你们对python 使用Twilio免费短信网关报警方法是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。