From: AceVest Date: Sat, 17 Feb 2018 10:31:15 +0000 (+0800) Subject: .... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=e0c1e4d5b887c87a2df2d099f29906fba4777f50;p=acecode.git .... --- diff --git a/RaspberryPi/get_lan_ip.py b/RaspberryPi/lanip/GetLanIp.py similarity index 87% rename from RaspberryPi/get_lan_ip.py rename to RaspberryPi/lanip/GetLanIp.py index 1cd27b2..4559fd8 100755 --- a/RaspberryPi/get_lan_ip.py +++ b/RaspberryPi/lanip/GetLanIp.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # ------------------------------------------------------------------------ -# File Name: get_lan_ip.py +# File Name: GetLanIp.py # Author: Zhao Yanbai # 2016-07-04 23:14:50 Monday CST # Description: none @@ -11,6 +11,7 @@ import fcntl import struct import os import sys +import time import re,urllib2 import smtplib import ConfigParser @@ -27,7 +28,8 @@ def get_ip_address(ifname): def SendMail(title, content) : cnfp = ConfigParser.ConfigParser() - cnfp.read('./mail.conf') + + cnfp.read(os.path.split(os.path.realpath(__file__))[0]+'/mail.conf') mail_host = cnfp.get('EMAIL', 'MAILHOST') # 服务器 mail_user = cnfp.get('EMAIL', 'MAILUSER') # 用户名 @@ -59,5 +61,11 @@ if __name__ == "__main__" : lanip[k] = get_ip_address(k) except : continue + while True : + try : + SendMail("LanIp", str(lanip)) + break + except: + time.sleep(1); + continue - SendMail("LanIp", str(lanip)) diff --git a/RaspberryPi/lanip/getlanip b/RaspberryPi/lanip/getlanip new file mode 100755 index 0000000..646c05e --- /dev/null +++ b/RaspberryPi/lanip/getlanip @@ -0,0 +1,31 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: acevest +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: get lan ip and send email +# Description: This service is used to get lan ip +### END INIT INFO + +# cp getlanip /etc/init.d/getlanip +# sudo update-rc.d getlanip defaults + + +case "$1" in +start) + echo "Starting Get RaspberryPi's LanIp" + /root/workspace/acecode/RaspberryPi/lanip/GetLanIp.py 2> /tmp/getlanip.log & + ;; + +stop) + echo "Stopping Get RaspberryPi's LanIp" + ;; + +*) + echo "Usage: service getlanip start|stop $1" + exit 0 + ;; +esac +exit 0 diff --git a/RaspberryPi/mail.conf.sample b/RaspberryPi/lanip/mail.conf.sample similarity index 100% rename from RaspberryPi/mail.conf.sample rename to RaspberryPi/lanip/mail.conf.sample