RPi 2B 自动发送获取的IP到固定邮箱
/*************************************************************************
* RPi 2B 自动发送获取的IP到固定邮箱
* 声明:
* 本文主要记录RPi 2B如何自动将IP以邮件的形式发送到邮箱。
*
* 2016-2-21 深圳 南山平山村 曾剑锋
************************************************************************/ 一、参考文档:
. RPi Email IP On Boot Debian
http://elinux.org/RPi_Email_IP_On_Boot_Debian
. How to convert list to string [duplicate]
http://stackoverflow.com/questions/5618878/how-to-convert-list-to-string
. Python for Loop Statements
http://www.tutorialspoint.com/python/python_for_loop.htm 二、cat bootSendEmail.py
#!/usr/bin/python import subprocess
import smtplib
from email.mime.text import MIMEText
import datetime # Change to your own account information
# Account Information
to = '64128306@qq.com' # Email to send to.
mail_user = 'zengjf42@163.com' # Email to send from.
mail_password = '填入授权密码' # Email password.
smtpserver = smtplib.SMTP('smtp.163.com') # Server to use. smtpserver.ehlo() # Says 'hello' to the server
smtpserver.starttls() # Start TLS encryption
smtpserver.ehlo()
smtpserver.login(mail_user, mail_password) # Log in to server
today = datetime.date.today() # Get current time/date arg='ip route list' # Linux command to retrieve ip addresses.
# Runs 'arg' in a 'hidden terminal'.
p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
data = p.communicate() # Get data from 'p terminal'. # get ip data
ip_lines = data[].splitlines()
ips = ""
for ip in ip_lines:
ips += ip + "\n" # Creates the text, subject, 'from', and 'to' of the message.
msg = MIMEText(ips)
msg['Subject'] = 'IPs For RaspberryPi on %s' % today.strftime('%b %d %Y')
msg['From'] = "zengjf42@163.com"
msg['To'] = "64128306@qq.com" # Sends the message
smtpserver.sendmail(mail_user, [to], msg.as_string()) # Closes the smtp server.
smtpserver.quit() 三、 将bootSendEmail.py放入/usr/bin/ 四、modify /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing. # Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
bootSendEmail.py # add this line
fi exit 五、重启系统,并查看邮箱:
default via 192.168.1.1 dev wlan0
default via 192.168.1.1 dev wlan0 metric
192.168.0.0/ dev eth0 proto kernel scope link src 192.168.0.5
192.168.1.0/ dev wlan0 proto kernel scope link src 192.168.1.102
192.168.1.0/ dev wlan0 proto kernel scope link src 192.168.1.102 metric
RPi 2B 自动发送获取的IP到固定邮箱的更多相关文章
- windows 远程桌面连接 RPi 2B
/************************************************************************* * windows 远程桌面连接 RPi 2B * ...
- windows ping RPi 2B
/************************************************************************* * windows ping RPi 2B * 声 ...
- RPi 2B python opencv camera demo example
/************************************************************************************** * RPi 2B pyt ...
- RPi 2B UART作为调试口或者普通串口
/************************************************************************************** * RPi 2B UAR ...
- python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客
python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客 undefined Python多线程抓取代理服务器 | Linux运维笔记 undefined java如 ...
- vue 项目使用 webpack 构建自动获取电脑ip地址
1.开发 H5 时移动端,经常会使用真机进行调试本地环境.webpack 配置服务器好多脚手架写的都是固定的,而在团队开发中需要每人配置自己的本机 ip 进行开发,每次开启开发环境的都需要修改,并且还 ...
- RPi 2B IPC webcam server
/**************************************************************************** * RPi 2B IPC webcam se ...
- 如何获取公网IP的mac地址
如何获取远程IP的mac地址 思路分析 由于java本身没有相关的jar包进行获取,所以这里介绍从其他的方面进行入手和实践 使用的工具对比: tcpdump tshark pcap4j 都可以达到抓包 ...
- PHP获取客户端IP
/** * 获取客户端IP */ function getClientIp() { $ip = 'unknown'; $unknown = 'unknown'; if (isset($_SERVER[ ...
随机推荐
- (转)linux性能优化总结
感谢博客http://sillycat.iteye.com提供的资料 linux性能检查(一)介绍和CPU 通常监控的子系统有: CPU Memory IO Network 应用类型 IO相关,处理大 ...
- Arcgis 10.1中空间连接功能
空间链接的作用:将面上的所有点的值加起来取平均值.赋值给面属性.(我们可以定义右击——定义合并规则 连接要素的字段映射参数中指定的合并规则仅适用于连接要素中的属性,且仅适用于多个要素与目标要素匹配 ( ...
- 同时安装vs2010和VS2012后IEnumerable<ModelClientValidationRule>编译错误
错误 类型“System.Web.Mvc.ModelClientValidationRule”同时存在于“c:\Program Files (x86)\Microsoft ASP.NET\ASP.NE ...
- UIImagePickerController拍照与摄像(转)
转载自:http://blog.sina.com.cn/s/blog_68edaff101019ppe.html (2012-11-23 14:38:40) 标签: ios iphone 拍照 摄像 ...
- parsing html in asp.net
http://stackoverflow.com/questions/5307374/parsing-html-page-in-asp-net http://htmlagilitypack.codep ...
- 自己实现的android树控件,android TreeView
1.开发原因 在项目中经常需要一个需要一个树状框架,这是非常常见的控件.不过可能是谷歌考虑到android是手机系统,界面宽度有限, 所以只提供了只有二级的ExpandableListView.虽然这 ...
- C#的历史及IDE总结
原Borland公司的首席研发设计师安德斯·海爾斯伯格(Anders Hejlsberg)在微軟開發了Visual J++ 1.0,很快的Visual J++由1.1版本升級到6.0版.SU ...
- jquery中json数据转换为字典
首先在前台页面中的json数据为 var recipe = {}; recipe["name"] = $("#name").val(); recipe[&quo ...
- Log4J 如何分开Logger输出
今天和两个同事讨论Log4j,他们都需要解决一个问题,怎么分开输出Logger.这么讲不清楚,举个例子: package com.gmail.at.ankyhe.log4jtest; import o ...
- 深入浅出 Java 8 Lambda 表达式
摘要:此篇文章主要介绍 Java8 Lambda 表达式产生的背景和用法,以及 Lambda 表达式与匿名类的不同等.本文系 OneAPM 工程师编译整理. Java 是一流的面向对象语言,除了部分简 ...