#!/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
import struct
import os
import sys
+import time
import re,urllib2
import smtplib
import ConfigParser
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') # 用户名
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))
--- /dev/null
+#!/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