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[ ...
随机推荐
- ajax的post用法
<button>点击之后,显示ajax返回的数据</button> 首先在页面上新建了一个按钮,点击这个按钮后,执行ajax操作,并将返回的字符串显示在按钮上. 下面是ajax ...
- Linux下mail/mailx命令发送邮件
最近看到项目中经常会用mail/mailx命令发送由java程序生成的report,比较新鲜.下面就简单介绍下mail/mailx命令用法.本文以mail命令举例(mail/mailx)效果都是一样的 ...
- PHP数组的操作
一.数组操作的基本函数数组的键名和值array_values($arr);获得数组的值array_keys($arr);获得数组的键名array_flip($arr);数组中的值与键名互换(如果有重复 ...
- 解决maven官方库中没有oracle jdbc驱动的问题:Missing artifact com.oracle:ojdbc14:jar:10.2.0.1.0
最近在整合SSHE项目时,想要添加Oracle驱动包时,Maven的pom.xml总是报Missing artifact com.oracle:ojdbc14:jar:10.2.0.1.0错, 下面我 ...
- 简单3d RPG游戏 之 004 攻击(二)
人物和怪物的攻击都有CD冷却,在PlayerAttack脚本中添加成员 //冷却倒计时 public float attackTimer; //CD冷却时间 public float coolDown ...
- AirDrop显示名字的修改问题
AirDrop的名字来源是设备登陆的iCloud账户 打开iCloud设置 把个人信息的名字改成自己的即可 前提是你的账号没有借朋友用过,如果朋友用过恰好没注销,你的通讯录又有你的朋友的号码,很有可能 ...
- linux 添加用户
1.下面就开始来说怎么添加新用户 我们以添加一个用户名为jorcen的新用户为例来说明,执行下面的命令: # useradd jorcen 2.那么就新用户就添加完成,但是没有任何信息,新用户添加完成 ...
- 【LCA】bzoj 2144:跳跳棋
2144: 跳跳棋 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 248 Solved: 121[Submit][Status][Discuss] ...
- Eclipse console文本换行
Eclipse换行主要有3个方面 格式化时编辑器文本换行 源代码注释文本换行 Eclipse控制台console显示文本换行 1和2参考 http://hi.baidu.com/ae6623/item ...
- asp 文件上传(无组件上传)
文件1.上传界面文件 upload.htm<html><head><meta http-equiv="Content-Language" conten ...