家里电视盒子刷的服务器,一个月电费二三块钱,同步文件用起来超级爽
100块钱的盒子,刷成Ubuntu
30块钱的监控UPS,停电能支撑8小时
1T的硬盘200块钱
接下来就是爽歪歪的家庭云盘,家庭服务器了
停电了,自动告诉我,公网IP变更了,邮件通知我
停电监测代码,就是ping 家里其他联网设备,能ping通就正常,不通就写下一个文件,利用阿里云监控,免费短信通知。
#!/bin/bash
pingserver=192.168.1.121
pingcmd()
{
ping -w 1 -c 1 $pingserver >/dev/null
result=`ping -w 1 -c 1 $pingserver|grep -q “ttl” && echo 0 ||echo 1`
return $result
}
pingcmd
ret=$?
if [ $ret -eq 1 ]
then
echo “0”>/var/www/html/checkpower.txt
else
echo “1”>/var/www/html/checkpower.txt
fi
#这是停电脚本,阿里云监控数据是否变更
下面是 公网IP变更通知
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
reload(sys)
sys.setdefaultencoding(‘utf8’)
import time
import smtplib
import urllib
import json
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
def sendEmail(smtpserver,username,password,sender,receiver,subject,msghtml):
msgRoot = MIMEMultipart(‘related’)
msgRoot[“To”] = ‘,’.join(receiver)
msgRoot[“From”] = sender
msgRoot[“Subject”] = subject
msgText = MIMEText(msghtml,’html’,’utf-8′)
msgRoot.attach(msgText)
#sendEmail
smtp = smtplib.SMTP_SSL()
smtp.connect(smtpserver)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()
def check_network():
result=urllib.urlopen(‘http://ip.taobao.com/outGetIpInfo?ip=myip&accessKey=alibaba-inc’).read()
return result
if __name__ == ‘__main__’:
ipaddr = check_network()
ip = json.loads(ipaddr)
ip = ip[“data”][“ip”]
txt = open(“ip.txt”)
oldip = txt.read()
if oldip <> ip:
txt = open(“ip.txt”,’w’)
txt.write(ip)
txt.close()
print time.strftime(“%Y-%m-%d %H:%M:%S”, time.localtime()),”Ip Diff”,ip
msghtml = “<p>Home Has New ip address: “+ip+”</p>”
msghtml += “<p>IP Address Of Route: “+ipaddr+”</p>”
sendEmail(‘smtp.***.com’,’**@163.com’,’****’,’***@163.com’,[‘a@***.cn’],’IP Address Of N1 Server’,msghtml)
else:
print time.strftime(“%Y-%m-%d %H:%M:%S”, time.localtime()), “Ip Same”,ip
未经允许不得转载:互联网骚操作 » 家里停电,自动监测,短信通知,家庭公网IP变更,自动切换通知
评论前必须登录!