import smtplib
from email.mime.text import MIMEText
import telnetlib
import time
def SendEmail(fromAdd,toAdd,subject,text):
_pwd = "Yeer2016@sudai" #授权码
msg = MIMEText(text)
msg["Subject"] = subject
msg["From"] = fromAdd
msg["To"] = toAdd
try:
s = smtplib.SMTP_SSL("smtp.sudaizhijia.com", 465)
s.login(fromAdd, _pwd)
s.sendmail(fromAdd, toAdd, msg.as_string())
s.quit()
print ("Success!")
except smtplib.SMTPException:
print('Falied!')
if __name__=='__main__':
server_list = ["47.93.33.37","59.110.142.122","47.93.44.44","1.8.15.2","47.94.239.155","47.93.53.16","47.93.216.61","47.93.44.44","39.105.94.61","59.110.173.167","59.110.142.122","47.93.33.37","39.106.78.73"," 47.95.10.116","39.106.47.33","39.105.94.61"]
while True:
for i in server_list:
time.sleep(10)
try:
telnetlib.Telnet(i, 22)
except OSError:
from_="tech-report@sudaizhijia.com" #你的邮箱 OSError发件地址
to_sender_address_list = ["wangdong@sudaizhijia.com"] #收件地址
subject = "服务器登录端口检查 " #邮件标题
text= '您的服务器IP:%s 22 端口 Telnet 不通了 请及时查看'%i #邮件内容
for i in to_sender_address_list:
SendEmail(from_,i,subject,text)
time.sleep(30)