/*************************************************************************
* 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. Git之不明觉厉11-利其器source tree

    前面10篇文章都在用命令行,虽然装逼不错,但是我想说一句,平时我也是用source tree比较多点,命令行一般都是在source tree的图形按钮找不到在哪里,就直接用命令行.对于初次用git的同 ...

  2. sql之透视

    1.透视原理:就是将查询结果进行转置 下面就举例来说明: 执行下面语句:检查是否含有表 dbo.Orders,如果有就将表删除: if OBJECT_ID('dbo.Orders','U') is n ...

  3. Qt的gzip模块实现

    一直没找到Qt中方便的gzip模块,于是自己动手,调用zlib模块实现了一份. 目标:  1.gzip的压缩与解压 2.内存中操作 3.方便的Qt接口   实现分析: gzip 压缩算法为 defla ...

  4. iOS10 权限崩溃问题-b

    手机升级了 iOS10 Beta,然后用正在开发的项目 装了个ipa包,发现点击有关 权限访问 直接Crash了,并在控制台输出了一些信息: This app has crashed because ...

  5. Hibernate简介2

    一.主配置 ◆查询缓存,同下面讲的缓存不太一样,它是针对HQL语句的缓存,即完全一样的语句再次执行时可以利用缓存数据.但是,查询缓存在一个交易系统(数据变更频繁,查询条件相同的机率并不大)中可能会起反 ...

  6. Windows平台上C++开发内存泄漏检查方法

    充分的利用调试工具可以非常方便地避免内存泄漏问题. 这里介绍两种方法,互为补充,第一种是VC编译器提供的方法,第二种是专用的内存泄漏检查工具Memmory Validator.这两种方法的基本原理是一 ...

  7. POJ 3393 Lucky and Good Months by Gregorian Calendar

    http://poj.org/problem?id=3393 题意 : 对于这篇长长的英语阅读,表示无语无语再无语,花了好长时间,终于读完了.题目中规定每周的周六日为假日,其他为工作日,若是一个月的第 ...

  8. 2013 Multi-University Training Contest 4 Who's Aunt Zhang

    看题就知道要用polya,但是当时没做出来,还是不是很熟悉polya!!! 总共有24种置换: 1. 不做任何旋转 K ^ (54 + 12 + 8) 2. 绕相对面中心的轴转 1) 90度 K ^ ...

  9. [topcoder]BadNeighbors

    http://community.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009 动态规划题.对于圈状的题目有了点感觉. 题 ...

  10. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-005-Pizza例子的订单流程()

    一. 1.订单流程定义文件order-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flo ...