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[ ...
随机推荐
- Oracle 执行计划说明
生成SQL的执行计划是Oracle在对SQL做硬解析时的一个非常重要的步骤,它制定出一个方案告诉Oracle在执行这条SQL时以什么样的方式访问数据:索引还是全表扫描,是Hash Join还是Nest ...
- DB2分区表删除和添加分区
1.数据库版本 2.具体procedure DROP PROCEDURE DB2USER.TOOLS_PARTITION_TABLE_SHOW (VARCHAR ()); )) /********** ...
- WPF中的多点触摸事件
UIElement在WPF4下添加了很多支持多点触摸的事件,通过它们可以在硬件支持的情况下处理多点触摸,以下通过代码来说明通过处理这些事件,我们可以做些什么: 一.触摸相关的多种事件,跟鼠标事件是对应 ...
- Redhat 显示系统版本号和内核版本号
1./etc/issue 和 /etc/redhat-release都是系统安装时默认的发行版本信息,通常安装好系统后文件内容不会发生变化.[root@rac1 mysql]# cat /etc/is ...
- PHP视频教程 > PHP面向对象编程视频教程
当前位置: 主页 > 编程开发 > PHP视频教程 > PHP面向对象编程视频教程 > kingstone金士顿手机内存卡16G仅65元 1.1.什么是面向对象和类 上传日期: ...
- 第2章 Git安装与设置
2.1 安装Git 略 2.2 设置Git 通过命令git config,用户可以把此类信息提供给本地版本库. 全局变量:在这台计算机上使用任何Git版本库时,这些全局变量的值都起作用.在相关命令中加 ...
- 可视化Windows服务定时任务
思路:1.新建一个<Windows服务项目>,在里面建服务文件(可以多个),用来做要执行的任务. 2.新建一个<Windows窗体应用程序>,在这个程序里管理服务.如:安装.卸 ...
- mysql日志详细解析 [转]
原文出处:http://pangge.blog.51cto.com/6013757/1319304 MySQL日志: 主要包含:错误日志.查询日志.慢查询日志.事务日志.二进制日志: 日志是mysql ...
- 字符串截取 方法 String b=a.substring(0, a.indexOf("乘坐"));
String b=a.substring(0, a.indexOf("乘坐"));
- awk 的一个奇怪异常
awk: cmd. line:1: (FILENAME=- FNR=192) fatal: print to "standard output" failed (No space ...