Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the alarm method of python using Twilio free SMS gateway?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about what is the alarm method of python using Twilio free SMS gateway. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Work reasons, to regularly check the status of the service, at first want to use Wechat official account, found that only the enterprise authentication account can send information to users, this program has been dropped. One day, when I read a book, I suddenly found that it is very convenient to send text messages for free on TWILIO. First, apply for twilio account address: https://www.twilio.com/ Note: you can use 163.com gmail.com in the mailbox, but you can't use QQ Mail. You can't get through. After applying for an account, you apply for a temporary phone number, which is used to send text messages to yourself.

Second, write python interface

Sms.py

Click (here) to collapse or open

# 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= "=", # ask for your own number

From_= ", # the mobile phone code applied for on the website can only be used to send messages.

Body=t.decode ("utf-8")) # Encoding password is sent in Chinese only using utf-8.

Print (message.sid)

Reference sms module

Click (here) to collapse or open

#! / 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% HRV% MVA% Swatch, time.localtime (time.time ()

Sk = socket.socket (socket.AF_INET, socket.SOCK_STREAM)

Sk.settimeout (1)

Try:

Sk.connect ((host,port))

Tweak host + "server" + str (port) + "connection is normal" + str (shijian)

# sms (t)

Print t

Except Exception:

Whitehost + "server" + str (port) + "unable to connect" + str (shijian)

Print w

Sms (w)

Sk.close ()

File = open ("/ root/script/ip.txt") # ip address is written as 192.16.0.1 root/script/ip.txt 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)

After reading the above, do you have any further understanding of the alarm method of python using Twilio free SMS gateway? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report