Show time in log messages
This commit is contained in:
parent
b65eaa947e
commit
50db350618
|
@ -5,12 +5,12 @@
|
||||||
# ip2e (IP to email) - Create the configuration file. |
|
# ip2e (IP to email) - Create the configuration file. |
|
||||||
# Created by clamsawd (clamsawd@openmailbox.org) |
|
# Created by clamsawd (clamsawd@openmailbox.org) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 27-10-2015 |
|
# Last update: 29-10-2015 |
|
||||||
# |
|
# |
|
||||||
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
|
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
version="0.5-alpha"
|
version="0.6-alpha"
|
||||||
|
|
||||||
#Import python-modules
|
#Import python-modules
|
||||||
import os
|
import os
|
||||||
|
|
|
@ -5,17 +5,18 @@
|
||||||
# ip2e (IP to email) - Run ip2e daemon. |
|
# ip2e (IP to email) - Run ip2e daemon. |
|
||||||
# Created by clamsawd (clamsawd@openmailbox.org) |
|
# Created by clamsawd (clamsawd@openmailbox.org) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 27-10-2015 |
|
# Last update: 29-10-2015 |
|
||||||
# |
|
# |
|
||||||
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
|
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
version="0.5-alpha"
|
version="0.6-alpha"
|
||||||
|
|
||||||
#Import python-modules
|
#Import python-modules
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
#Check if your system use Python 3.x
|
#Check if your system use Python 3.x
|
||||||
if sys.version_info<(3,0):
|
if sys.version_info<(3,0):
|
||||||
|
@ -140,14 +141,15 @@ exec(open("ip2e-conf.py").read())
|
||||||
|
|
||||||
#Run ip2e daemon
|
#Run ip2e daemon
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
print ("[ip2e-daemon] Initialized ip2e-daemon v"+version+" (Ctrl+C to stop)")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
|
print ("[ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+" (Ctrl+C to stop)")
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
print ("[ip2e-daemon] Log in "+os.environ["HOME"]+"/.ip2e/ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["HOME"]+"/.ip2e/ip2e.log")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
print ("[ip2e-daemon] Log in "+os.environ["USERPROFILE"]+"\.ip2e\\ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Log in "+os.environ["USERPROFILE"]+"\.ip2e\\ip2e.log")
|
||||||
os.system("echo [ip2e-daemon] Initialized ip2e-daemon v"+version+" > ip2e.log")
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] Initialized ip2e-daemon v"+version+" > ip2e.log")
|
||||||
print ("[ip2e-daemon] Waiting 60 seconds...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds...")
|
||||||
os.system("echo [ip2e-daemon] Waiting 60 seconds... >> ip2e.log")
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] Waiting 60 seconds... >> ip2e.log")
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
os.system("sleep 60")
|
os.system("sleep 60")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
|
@ -158,8 +160,9 @@ PublicIP = 1
|
||||||
while PublicIP <= 2:
|
while PublicIP <= 2:
|
||||||
GetCurrentIP = 1
|
GetCurrentIP = 1
|
||||||
while GetCurrentIP <= 2:
|
while GetCurrentIP <= 2:
|
||||||
print ("[ip2e-daemon] IP Updating...")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
os.system("echo [ip2e-daemon] IP Updating... >> ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
||||||
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] IP Updating... >> ip2e.log")
|
||||||
NewIPRaw = os.popen('curl -s icanhazip.com').read()
|
NewIPRaw = os.popen('curl -s icanhazip.com').read()
|
||||||
NewIP = NewIPRaw.strip()
|
NewIP = NewIPRaw.strip()
|
||||||
#NewIP = os.popen('curl -s http://ip.appspot.com/').read()
|
#NewIP = os.popen('curl -s http://ip.appspot.com/').read()
|
||||||
|
@ -169,39 +172,44 @@ while PublicIP <= 2:
|
||||||
if NewIP != "":
|
if NewIP != "":
|
||||||
GetCurrentIP += 2
|
GetCurrentIP += 2
|
||||||
else:
|
else:
|
||||||
print ("[ip2e-daemon] Error getting IP")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
os.system("echo [ip2e-daemon] Error getting IP >> ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
||||||
print ("[ip2e-daemon] Retrying in 5 seconds...")
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] Error getting IP >> ip2e.log")
|
||||||
os.system("echo [ip2e-daemon] Retrying in 5 seconds... >> ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
||||||
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds... >> ip2e.log")
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
os.system("sleep 5")
|
os.system("sleep 5")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.system("ping -n 5 localhost>nul")
|
os.system("ping -n 5 localhost>nul")
|
||||||
exec(open("current-ip.py").read())
|
exec(open("current-ip.py").read())
|
||||||
if CurrentIP == NewIP:
|
if CurrentIP == NewIP:
|
||||||
print ("[ip2e-daemon] IP has not changed")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
os.system("echo [ip2e-daemon] IP has not changed >> ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
|
||||||
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] IP has not changed >> ip2e.log")
|
||||||
else:
|
else:
|
||||||
print ("[ip2e-daemon] New IP - From "+CurrentIP+" to "+NewIP)
|
CurrentTime = time.strftime("%H:%M")
|
||||||
os.system("echo [ip2e-daemon] New IP - From "+CurrentIP+" to "+NewIP+" >> ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
|
||||||
MailMessage="[ip2e-daemon] Email was sent successfully"
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP+" >> ip2e.log")
|
||||||
SendEmailOK = 1
|
SendEmailOK = 1
|
||||||
while SendEmailOK <= 2:
|
while SendEmailOK <= 2:
|
||||||
|
CurrentTime = time.strftime("%H:%M")
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
ErrorSendEmail = os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u '[ip2e-daemon] IP has changed' -m '[ip2e] New IP is '"+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
|
ErrorSendEmail = os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u '[ip2e-daemon] ["+CurrentTime+"] IP has changed' -m '[ip2e] New IP is '"+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
ErrorSendEmail = os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u [ip2e-daemon] IP has changed -m [ip2e] New IP is "+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
|
ErrorSendEmail = os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u [ip2e-daemon] ["+CurrentTime+"] IP has changed -m [ip2e] New IP is "+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
|
||||||
if ErrorSendEmail == 0:
|
if ErrorSendEmail == 0:
|
||||||
MailMessage="[ip2e-daemon] Email was sent successfully"
|
CurrentTime = time.strftime("%H:%M")
|
||||||
|
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Email was sent successfully"
|
||||||
print (MailMessage+" ("+ToEmail+")")
|
print (MailMessage+" ("+ToEmail+")")
|
||||||
os.system("echo "+MailMessage+" to "+ToEmail+" >> ip2e.log")
|
os.system("echo "+MailMessage+" to "+ToEmail+" >> ip2e.log")
|
||||||
SendEmailOK += 2
|
SendEmailOK += 2
|
||||||
else:
|
else:
|
||||||
MailMessage="[ip2e-daemon] Fail to send email"
|
CurrentTime = time.strftime("%H:%M")
|
||||||
|
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Fail to send email"
|
||||||
print (MailMessage+" ("+ToEmail+")")
|
print (MailMessage+" ("+ToEmail+")")
|
||||||
os.system("echo "+MailMessage+" to "+ToEmail+" >> ip2e.log")
|
os.system("echo "+MailMessage+" to "+ToEmail+" >> ip2e.log")
|
||||||
print ("[ip2e-daemon] Retrying in 5 seconds...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds...")
|
||||||
os.system("echo [ip2e-daemon] Retrying in 5 seconds... >> ip2e.log")
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] Retrying in 5 seconds... >> ip2e.log")
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
os.system("sleep 5")
|
os.system("sleep 5")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
|
@ -219,6 +227,7 @@ while PublicIP <= 2:
|
||||||
ip2eIPcf.close()
|
ip2eIPcf.close()
|
||||||
createNewip2eIPcf()
|
createNewip2eIPcf()
|
||||||
writeNewip2eIPcf()
|
writeNewip2eIPcf()
|
||||||
print ("[ip2e-daemon] Next update in 10 minutes...")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
os.system("echo [ip2e-daemon] Next update in 10 minutes... >> ip2e.log")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
|
||||||
|
os.system("echo [ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes... >> ip2e.log")
|
||||||
WaitTenMinutes()
|
WaitTenMinutes()
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
# ip2e (IP to email) - See the log file. |
|
# ip2e (IP to email) - See the log file. |
|
||||||
# Created by clamsawd (clamsawd@openmailbox.org) |
|
# Created by clamsawd (clamsawd@openmailbox.org) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 27-10-2015 |
|
# Last update: 29-10-2015 |
|
||||||
# |
|
# |
|
||||||
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
|
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
version="0.5-alpha"
|
version="0.6-alpha"
|
||||||
|
|
||||||
#Import python-modules
|
#Import python-modules
|
||||||
import os
|
import os
|
||||||
|
|
Loading…
Reference in New Issue
Block a user