#!/usr/bin/python
# -*- coding:UTF-8 -*-
#测试发送邮件163邮箱发送到qq邮箱
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr msg=MIMEText('请输入内容','plain','utf-8')
msg['From']='发送邮箱昵称 <xxx@163.com>'
msg['To']='接收邮箱昵称 <xxx@qq.com>'
#主题(主题不能为test等会被拦截)
msg['Subject']=Header('niceday','utf-8') server=smtplib.SMTP()
server.connect('smtp.163.com',25)
#密码为第三方客户端密码不是登录密码
server.login('xxx@163.com','密码')
server.sendmail('xxx@163.com','xxx@qq.com',msg.as_string())
server.quit()
#-*- coding: utf-8 -*-
#获取树莓派所有网络设备IP
import array
import struct
import socket
import fcntl SIOCGIFCONF = 0x8912
SIOCGIFADDR = 0x8915
BYTES = 4096
sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
names = array.array('B',b'\0' * BYTES)
bytelen = struct.unpack('iL', fcntl.ioctl(sck.fileno(), SIOCGIFCONF, struct.pack('iL', BYTES, names.buffer_info()[0])))[0]
namestr = names.tostring()
ifaces = [namestr[i:i+32].split('\0', 1)[0] for i in range(0, bytelen, 32)] #再获取每个接口的IP地址
iplist = []
for ifname in ifaces:
ip = socket.inet_ntoa(fcntl.ioctl(sck.fileno(),0x8915,struct.pack('256s',ifname[:15]))[20:24])
iplist.append(ifname+':'+ip) ip = '\r\n'.join(iplist)
print iplist
#检测网络
import urllib
def check_network():
while True:
try:
result=urllib.urlopen('http://baidu.com').read()
print result
print "Network is Ready!"
break
except Exception , e:
print e
print "Netwofk is not ready,Sleep 5s..."
time.sleep(5)
return True check_network()