python3练习-发送IP地址到邮箱(使用日志)
看了下python下的logging模块,和java的log4j差不多,把之前的代码改为使用log配置的方式实现功能(需求和之前的相同,地址"http://www.cnblogs.com/GYoungBean/p/6510508.html")
#! usr/bin/env python3
# -*- coding:utf-8 -*- import socket
import threading
import logging.config now_ip = "" def _get_ip_win():
ips = socket.gethostbyname_ex(socket.gethostname())
for s in ips[2]:
if s.startswith(''):
return s def checkIP(start_ip):
global now_ip
if start_ip != now_ip:
logger_mail.error('Send Mail:the old IP is:%s.Now,the new IP is:%s' % (now_ip,start_ip))
now_ip = start_ip
else:
logger_root.info('IP address not change,the old IP is:%s---the new IP is:%s' % (start_ip, now_ip))
new_ip = _get_ip_win()
t = threading.Timer(3600.0, checkIP,(new_ip,))
t.start() if __name__ == '__main__':
logging.config.fileConfig("./logging.conf")
logger_mail = logging.getLogger('mail')
logger_root = logging.getLogger('root')
start_ip,now_ip = _get_ip_win(),_get_ip_win()
checkIP(start_ip)
日志配置如下(logging.conf):
[loggers]
keys=root,mail [handlers]
keys=consoleHandler,fileHandler,mailHandler [formatters]
keys=simpleFormatter [formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s - [%(filename)s:%(lineno)s]
datefmt= [logger_root]
level=INFO
handlers=consoleHandler,fileHandler [logger_mail]
level=ERROR
handlers=mailHandler,fileHandler
qualname=mail
propagate=0 [handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=simpleFormatter
args=(sys.stdout,) [handler_fileHandler]
class=FileHandler
level=INFO
formatter=simpleFormatter
args=('./ipchange.log', 'a') [handler_mailHandler]
class=handlers.SMTPHandler
level=ERROR
formatter=simpleFormatter
args=(('xxx',25), 'xxx', ['xxx','xxx'], 'NOTICE!!!--PC IP CHANGED', ('xxx', 'xxx'))
python3练习-发送IP地址到邮箱(使用日志)的更多相关文章
- python3练习-发送IP地址到邮箱
需求: 从外网通过VPN访问内网,并登录电脑A.在电脑A通过共享文件夹(需要\\IP的方式访问)访问到内网电脑B,由于电脑B的WI-FI的IP地址会变化,所以当电脑B的I访问路径需要获知电脑B的最新I ...
- 树莓派开机发送IP地址到邮箱
树莓派使用的wifi联网,在宿舍使用的是公共网络,不能设置静态ip,每次树莓派上电开机后ip地址可能会改变,所以让树莓派开机联网后自动发送ip地址到QQ邮箱 一.安装mutt和msmtp mutt: ...
- 让树莓派自动上报IP地址到邮箱,二代B
由于我使用树莓派的场景大多数是在没有显示器.只用terminal连接它的情况下,所以,它的IP地址有时会在重启之后变掉(DHCP的),导致我无法通过terminal连接上它.然后我又要很麻烦地登录路由 ...
- 树莓派获取ip地址发送到邮箱
公网 ip.sh curl http://members.3322.org/dyndns/getip >>/email/ip.log python /email/mail.py ##### ...
- C#服务器获取客户端IP地址以及归属地探秘
背景:博主本是一位Windows桌面应用程序开发工程师,对网络通信一知半解.一日老婆逛完某宝,问:"为什么他们知道我的地址呢,他们是怎么获取我的地址的呢?" 顺着这个问题我们的探秘 ...
- OpenStack中虚拟机获取不到IP地址的解决方法
OpenStack源码交流群: 538850354 系统环境: centos6.5 + icehouse多节点部署 问题描述: 使用测试镜像cirros,虚拟机实例可以正常启动,但是不能从IP池中获取 ...
- 常用正则表达式大全,手机、电话、邮箱、身份证(最严格的验证)、IP地址、网址、日期等
<script type="text/javascript">/* * 手机号码格式 * 只允许以13.15.18开头的号码 * 如:13012345678.15929 ...
- php使用过滤器filter_var轻松验证邮箱url和ip地址等
以前使用php的时候还不知道有过滤器filter这玩意,那时候判断邮箱.url和ip地址格式是否符合都是用正则表达式.后来随着使用的逐渐深入,才知道在php中也可以使用内置的函数库过滤器filter来 ...
- 验证中文、英文、电话、手机、邮箱、数字、数字和字母、Url地址和Ip地址的正则表达式
Helper类代码 public class Helper { #region 单列循环 private Helper() { } private static Helper instance = n ...
随机推荐
- 【JVM】-NO.113.JVM.1 -【JDK11 HashMap详解-0-全局-put】
Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
- openshift 容器云从入门到崩溃之七《数据持久化》
数据持久化常用的有两种: hostPath 挂载容器宿主机的本地文件夹,直接修改pod的配置 volumes: - hostPath: path: /data/logging-es type: '' ...
- iOS UI基础-21 WKWebView
WKWebView,直接显示网页,需要引入第三方类:https://github.com/marcuswestin/WebViewJavascriptBridge 加上进度条代码,很完美使用 webV ...
- svn更新项目之后,项目报错一大堆并且tomcat部署项目时找不到项目
原因是:svn更新项目以后jdk路劲不对,需要使用自己安装的jdk,即可.具体步骤如下 第一步:右击项目-->Build path-->Configure Build path... 第二 ...
- TP连接数据库报错:SQLSTATE[HY000] [2002] No such file or directory
连接数据库报错:“SQLSTATE[HY000] [2002] No such file or directory”. 出现这个问题的原因是PDO无法找到mysql.sock或者mysqld.soc ...
- select2 api参数中文文档
select2 api参数的文档 具体参数可以参考一下: 参数 类型 描述 Width 字符串 控制 宽度 样式属性的Select2容器div minimumInputLength int 最小数 ...
- Git换行符是如何精确控制的
Git换行符是如何精确控制的 Checkout Windows-style, commit Unix-style Git will convert LF to CRLF when checking o ...
- 新装Windows Server 2008 r2无法连接有线网络
新装的Windows Server 2008 r2没有网卡驱动,所以没有网络适配器. 首先,我在相同的型号电脑上查到这个主板的网卡驱动安装的是Intel(R) Ethernet Coinnection ...
- vue计算属性和侦听器
一.计算属性: main.js: var app = new Vue({ el: '#app', data: { math: 80, physics: 90, english: 30 }, compu ...
- 《CSS世界》读书笔记(八)
<!-- <CSS世界>张鑫旭著 --> 替换元素和非替换元素的距离有多远? 观点1:替换元素和非替换元素之间只隔了一个src属性! 在Firefox浏览器下,没有src属性的 ...