/*************************************************************************
* 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到固定邮箱的更多相关文章

  1. windows 远程桌面连接 RPi 2B

    /************************************************************************* * windows 远程桌面连接 RPi 2B * ...

  2. windows ping RPi 2B

    /************************************************************************* * windows ping RPi 2B * 声 ...

  3. RPi 2B python opencv camera demo example

    /************************************************************************************** * RPi 2B pyt ...

  4. RPi 2B UART作为调试口或者普通串口

    /************************************************************************************** * RPi 2B UAR ...

  5. python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客

    python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客 undefined Python多线程抓取代理服务器 | Linux运维笔记 undefined java如 ...

  6. vue 项目使用 webpack 构建自动获取电脑ip地址

    1.开发 H5 时移动端,经常会使用真机进行调试本地环境.webpack 配置服务器好多脚手架写的都是固定的,而在团队开发中需要每人配置自己的本机 ip 进行开发,每次开启开发环境的都需要修改,并且还 ...

  7. RPi 2B IPC webcam server

    /**************************************************************************** * RPi 2B IPC webcam se ...

  8. 如何获取公网IP的mac地址

    如何获取远程IP的mac地址 思路分析 由于java本身没有相关的jar包进行获取,所以这里介绍从其他的方面进行入手和实践 使用的工具对比: tcpdump tshark pcap4j 都可以达到抓包 ...

  9. PHP获取客户端IP

    /** * 获取客户端IP */ function getClientIp() { $ip = 'unknown'; $unknown = 'unknown'; if (isset($_SERVER[ ...

随机推荐

  1. [Python 标准库]第一章 文本

    Chapter01 文本 1.1 string - 文本常量和模板 作用:包含处理文本的常量和类. 1.1.1 函数 capwords(s):字符串中所有单词首字母大写 maketrans():创建转 ...

  2. dell inspiorn 14vr 1616b ubuntu 无线网卡的问题

    找到两个解决方法: 1 找 网卡驱动下载: 用命令 以下 from :http://zhidao.baidu.com/link?url=k6QNIdJlbRyZJSEW1cVUs_1p4Jv-73c8 ...

  3. Understanding Responsive Web Design: Cross-browser Compatibility

    http://www.sitepoint.com/understanding-responsive-web-design-cross-browser-compatibility/ In the las ...

  4. MyBatis对不同数据库的主键生成策略

    本文转自:http://289972458.iteye.com/blog/1001851  http://hi.baidu.com/zim_it/blog/item/8a2bd11205f5b56ec ...

  5. js获取当前浏览器页面高度及宽度信息的方法

    var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); var scroll ...

  6. 我的PHP之旅--XML初步

    什么是XML? XML是可拓展标记语言,它和XHTML很像.但它和XHTML的目的性不一样,XHTML负责展示数据,而XML负责保存或交换传输数据. 而且XML可拓展,它没有固定的标签.它的标签可以自 ...

  7. python学习笔记10(函数一): 函数使用、调用、返回值

    一.函数的定义 在某些编程语言当中,函数声明和函数定义是区分开的(在这些编程语言当中函数声明和函数定义可以出现在不同的文件中,比如C语言),但是在Python中,函数声明和函数定义是视为一体的.在Py ...

  8. java第六课 oop

    java oop 1.面向过程的结构化程序设计弊端:方法和数据结构都是毫无规律的定义在程序中任何位置        方法定义和方法要处理的数据结构也都是分开定义 2.对象:每new一次,就创建1个新对 ...

  9. VS2008的默认打开重置为VS2008

  10. MySQL查询本周、上周、本月、上个月份数据的sql代码(转)

    感谢:http://www.jb51.net/article/32277.htm ----------------------------------------------------------- ...