]> Zhao Yanbai Git Server - acecode.git/commitdiff
....
authorAceVest <zhaoyanbai@126.com>
Sat, 17 Feb 2018 10:31:15 +0000 (18:31 +0800)
committerAceVest <zhaoyanbai@126.com>
Sat, 17 Feb 2018 10:31:15 +0000 (18:31 +0800)
RaspberryPi/lanip/GetLanIp.py [moved from RaspberryPi/get_lan_ip.py with 87% similarity]
RaspberryPi/lanip/getlanip [new file with mode: 0755]
RaspberryPi/lanip/mail.conf.sample [moved from RaspberryPi/mail.conf.sample with 100% similarity]

similarity index 87%
rename from RaspberryPi/get_lan_ip.py
rename to RaspberryPi/lanip/GetLanIp.py
index 1cd27b283b03a6327dc5d33015e35fdc1f7fbde3..4559fd8adceade28425642d860c0b659fe65af61 100755 (executable)
@@ -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 (executable)
index 0000000..646c05e
--- /dev/null
@@ -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