Better indent source code
This commit is contained in:
parent
0e44d9be46
commit
092a5799ca
160
ip2e-config.py
160
ip2e-config.py
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
# ip2e (IP to email) - Create the configuration file. |
|
# ip2e (IP to email) - Create the configuration file. |
|
||||||
# Created by q3aql (q3aql@openmailbox.org) |
|
# Created by q3aql (q3aql@protonmail.ch) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 01-03-2016 |
|
# Last update: 03-04-2021 |
|
||||||
# |
|
# |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
|
@ -17,75 +17,75 @@ import sys
|
||||||
|
|
||||||
#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):
|
||||||
print ("")
|
print ("")
|
||||||
print ("You need python 3.x to run this program.")
|
print ("* You need python 3.x to run this program.")
|
||||||
print ("")
|
print ("")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
#Function to clear screen
|
#Function to clear screen
|
||||||
def ClearScreen():
|
def ClearScreen():
|
||||||
if sys.platform == "cygwin":
|
if sys.platform == "cygwin":
|
||||||
print (300 * "\n")
|
print (300 * "\n")
|
||||||
elif os.name == "posix":
|
elif os.name == "posix":
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.system("cls")
|
os.system("cls")
|
||||||
else:
|
else:
|
||||||
print ("Error: Unable clear screen")
|
print ("* Error: Unable clear screen")
|
||||||
|
|
||||||
#Detect system & PATH of user folder
|
#Detect system & PATH of user folder
|
||||||
if os.path.exists("/storage/sdcard0"):
|
if os.path.exists("/storage/sdcard0"):
|
||||||
HOMESCARD0="/storage/sdcard0/Android/data"
|
HOMESCARD0="/storage/sdcard0/Android/data"
|
||||||
os.chdir(HOMESCARD0)
|
os.chdir(HOMESCARD0)
|
||||||
print ("Android (Posix) detected")
|
print ("Android (Posix) detected")
|
||||||
elif os.name == "posix":
|
elif os.name == "posix":
|
||||||
os.chdir(os.environ["HOME"])
|
os.chdir(os.environ["HOME"])
|
||||||
print ("Unix (Posix) detected")
|
print ("Unix (Posix) detected")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.chdir(os.environ["USERPROFILE"])
|
os.chdir(os.environ["USERPROFILE"])
|
||||||
print ("Windows detected")
|
print ("Windows detected")
|
||||||
|
|
||||||
if not os.path.exists(".ip2e"):
|
if not os.path.exists(".ip2e"):
|
||||||
os.makedirs(".ip2e")
|
os.makedirs(".ip2e")
|
||||||
os.chdir(".ip2e")
|
os.chdir(".ip2e")
|
||||||
if os.path.exists(".ip2e"):
|
if os.path.exists(".ip2e"):
|
||||||
os.chdir(".ip2e")
|
os.chdir(".ip2e")
|
||||||
|
|
||||||
if os.path.isfile("ip2e.conf"):
|
if os.path.isfile("ip2e.conf"):
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
print ("")
|
print ("")
|
||||||
print ("** ip2e-config v"+version+" **")
|
print ("** ip2e-config v"+version+" **")
|
||||||
print ("")
|
print ("")
|
||||||
print (" - Detected a previous configuration file.")
|
print (" - Detected a previous configuration file.")
|
||||||
print (" - Do you want to overwrite or check the current configuration?")
|
print (" - Do you want to overwrite or check the current configuration?")
|
||||||
print ("")
|
print ("")
|
||||||
print (" * (o) - overwrite (create new configuration)")
|
print (" * (o) - overwrite (create new configuration)")
|
||||||
print (" * (c) - check and test the current configuration")
|
print (" * (c) - check and test the current configuration")
|
||||||
print ("")
|
print ("")
|
||||||
OverWriteOrCheck=input("- [Default: check and test] Choose an option; ")
|
OverWriteOrCheck=input("- [Default: check and test] Choose an option; ")
|
||||||
if OverWriteOrCheck == "o" or OverWriteOrCheck == "O":
|
if OverWriteOrCheck == "o" or OverWriteOrCheck == "O":
|
||||||
print ("Create new configuration")
|
print ("Create new configuration")
|
||||||
else:
|
else:
|
||||||
exec(open("ip2e.conf").read())
|
exec(open("ip2e.conf").read())
|
||||||
#Import smtplib
|
#Import smtplib
|
||||||
import smtplib
|
import smtplib
|
||||||
try:
|
try:
|
||||||
server = smtplib.SMTP(SmtpFromEmail)
|
server = smtplib.SMTP(SmtpFromEmail)
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.starttls()
|
server.starttls()
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.login(FromEmailUser,FromEmailPass)
|
server.login(FromEmailUser,FromEmailPass)
|
||||||
server.quit()
|
server.quit()
|
||||||
print ("")
|
print ("")
|
||||||
print ("* Test OK")
|
print ("* Test OK")
|
||||||
print ("")
|
print ("")
|
||||||
PauseExit=input("+ Press ENTER to exit ")
|
PauseExit=input("+ Press ENTER to exit ")
|
||||||
except:
|
except:
|
||||||
print ("")
|
print ("")
|
||||||
print ("* Failed to connect ("+SmtpFromEmail+")")
|
print ("* Failed to connect ("+SmtpFromEmail+")")
|
||||||
print ("")
|
print ("")
|
||||||
PauseExit=input("+ Press ENTER to exit ")
|
PauseExit=input("+ Press ENTER to exit ")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
#Set variables of 'ip2e.conf'
|
#Set variables of 'ip2e.conf'
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
|
@ -100,7 +100,7 @@ ToEmail=input("- Type the email receiver: ")
|
||||||
|
|
||||||
#Create 'ip2e.conf'
|
#Create 'ip2e.conf'
|
||||||
if os.path.isfile("ip2e.conf"):
|
if os.path.isfile("ip2e.conf"):
|
||||||
os.remove("ip2e.conf")
|
os.remove("ip2e.conf")
|
||||||
ip2ecf=open('ip2e.conf','w')
|
ip2ecf=open('ip2e.conf','w')
|
||||||
ip2ecf.close()
|
ip2ecf.close()
|
||||||
ip2ecf=open('ip2e.conf','a')
|
ip2ecf=open('ip2e.conf','a')
|
||||||
|
@ -126,25 +126,25 @@ readfile.close()
|
||||||
print ("")
|
print ("")
|
||||||
TestConnection=input("- [Default: y] Test connection with your configuration (y/n): ")
|
TestConnection=input("- [Default: y] Test connection with your configuration (y/n): ")
|
||||||
if TestConnection == "n":
|
if TestConnection == "n":
|
||||||
print ("Exiting...")
|
print ("Exiting...")
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
exec(open("ip2e.conf").read())
|
exec(open("ip2e.conf").read())
|
||||||
#Import smtplib
|
#Import smtplib
|
||||||
import smtplib
|
import smtplib
|
||||||
try:
|
try:
|
||||||
server = smtplib.SMTP(SmtpFromEmail)
|
server = smtplib.SMTP(SmtpFromEmail)
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.starttls()
|
server.starttls()
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.login(FromEmailUser,FromEmailPass)
|
server.login(FromEmailUser,FromEmailPass)
|
||||||
server.quit()
|
server.quit()
|
||||||
print ("")
|
print ("")
|
||||||
print ("* Test OK")
|
print ("* Test OK")
|
||||||
print ("")
|
print ("")
|
||||||
PauseExit=input("+ Press ENTER to exit ")
|
PauseExit=input("+ Press ENTER to exit ")
|
||||||
except:
|
except:
|
||||||
print ("")
|
print ("")
|
||||||
print ("* Failed to connect ("+SmtpFromEmail+")")
|
print ("* Failed to connect ("+SmtpFromEmail+")")
|
||||||
print ("")
|
print ("")
|
||||||
PauseExit=input("+ Press ENTER to exit ")
|
PauseExit=input("+ Press ENTER to exit ")
|
||||||
|
|
420
ip2e-daemon.py
420
ip2e-daemon.py
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
# ip2e (IP to email) - Run ip2e daemon. |
|
# ip2e (IP to email) - Run ip2e daemon. |
|
||||||
# Created by q3aql (q3aql@openmailbox.org) |
|
# Created by q3aql (q3aql@protonmail.ch) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 01-03-2016 |
|
# Last update: 03-04-2021 |
|
||||||
# |
|
# |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
|
@ -22,149 +22,149 @@ import random
|
||||||
|
|
||||||
#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):
|
||||||
print ("")
|
print ("")
|
||||||
print ("You need python 3.x to run this program.")
|
print ("You need python 3.x to run this program.")
|
||||||
print ("")
|
print ("")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
#Function to clear screen
|
#Function to clear screen
|
||||||
def ClearScreen():
|
def ClearScreen():
|
||||||
if sys.platform == "cygwin":
|
if sys.platform == "cygwin":
|
||||||
print (300 * "\n")
|
print (300 * "\n")
|
||||||
elif os.name == "posix":
|
elif os.name == "posix":
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.system("cls")
|
os.system("cls")
|
||||||
else:
|
else:
|
||||||
print ("Error: Unable clear screen")
|
print ("Error: Unable clear screen")
|
||||||
|
|
||||||
#Detect system & PATH of user folder
|
#Detect system & PATH of user folder
|
||||||
if os.path.exists("/storage/sdcard0"):
|
if os.path.exists("/storage/sdcard0"):
|
||||||
HOMESCARD0="/storage/sdcard0/Android/data"
|
HOMESCARD0="/storage/sdcard0/Android/data"
|
||||||
os.chdir(HOMESCARD0)
|
os.chdir(HOMESCARD0)
|
||||||
LogFile=HOMESCARD0+"/ip2e/ip2e.log"
|
LogFile=HOMESCARD0+"/ip2e/ip2e.log"
|
||||||
LockFile=HOMESCARD0+"/ip2e/ip2e.lock"
|
LockFile=HOMESCARD0+"/ip2e/ip2e.lock"
|
||||||
print ("Android (Posix) detected")
|
print ("Android (Posix) detected")
|
||||||
elif os.name == "posix":
|
elif os.name == "posix":
|
||||||
os.chdir(os.environ["HOME"])
|
os.chdir(os.environ["HOME"])
|
||||||
LogFile=os.environ["HOME"]+"/.ip2e/ip2e.log"
|
LogFile=os.environ["HOME"]+"/.ip2e/ip2e.log"
|
||||||
LockFile=os.environ["HOME"]+"/.ip2e/ip2e.lock"
|
LockFile=os.environ["HOME"]+"/.ip2e/ip2e.lock"
|
||||||
print ("Unix (Posix) detected")
|
print ("Unix (Posix) detected")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.chdir(os.environ["USERPROFILE"])
|
os.chdir(os.environ["USERPROFILE"])
|
||||||
LogFile=os.environ["USERPROFILE"]+"\\.ip2e\\ip2e.log"
|
LogFile=os.environ["USERPROFILE"]+"\\.ip2e\\ip2e.log"
|
||||||
LockFile=os.environ["USERPROFILE"]+"\\.ip2e\\ip2e.lock"
|
LockFile=os.environ["USERPROFILE"]+"\\.ip2e\\ip2e.lock"
|
||||||
print ("Windows detected")
|
print ("Windows detected")
|
||||||
|
|
||||||
if not os.path.exists(".ip2e"):
|
if not os.path.exists(".ip2e"):
|
||||||
os.makedirs(".ip2e")
|
os.makedirs(".ip2e")
|
||||||
os.chdir(".ip2e")
|
os.chdir(".ip2e")
|
||||||
if os.path.exists(".ip2e"):
|
if os.path.exists(".ip2e"):
|
||||||
os.chdir(".ip2e")
|
os.chdir(".ip2e")
|
||||||
|
|
||||||
#Check if exists 'ip2e.conf'
|
#Check if exists 'ip2e.conf'
|
||||||
if os.path.isfile("ip2e.conf"):
|
if os.path.isfile("ip2e.conf"):
|
||||||
print ("ip2e.conf exists")
|
print ("ip2e.conf exists")
|
||||||
else:
|
else:
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
print ("")
|
print ("")
|
||||||
print ("* The configuration file doesn't exist")
|
print ("* The configuration file doesn't exist")
|
||||||
print ("")
|
print ("")
|
||||||
print ("* You can create it if you run 'ip2e-config.py'")
|
print ("* You can create it if you run 'ip2e-config.py'")
|
||||||
print ("")
|
print ("")
|
||||||
PauseExit=input("+ Press ENTER to exit ")
|
PauseExit=input("+ Press ENTER to exit ")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
#Check if exists 'IP.log'
|
#Check if exists 'IP.log'
|
||||||
if os.path.isfile("IP.log"):
|
if os.path.isfile("IP.log"):
|
||||||
print ("IP.log exists")
|
print ("IP.log exists")
|
||||||
else:
|
else:
|
||||||
print ("IP.log created")
|
print ("IP.log created")
|
||||||
ip2eIPcf=open('IP.log','w')
|
ip2eIPcf=open('IP.log','w')
|
||||||
ip2eIPcf.close()
|
ip2eIPcf.close()
|
||||||
ip2eIPcf=open('IP.log','a')
|
ip2eIPcf=open('IP.log','a')
|
||||||
ip2eIPcf.write('0.0.0.0')
|
ip2eIPcf.write('0.0.0.0')
|
||||||
ip2eIPcf.close()
|
ip2eIPcf.close()
|
||||||
|
|
||||||
#Import variables from ip2e.conf
|
#Import variables from ip2e.conf
|
||||||
exec(open("ip2e.conf").read())
|
exec(open("ip2e.conf").read())
|
||||||
|
|
||||||
#Import native OS color scheme
|
#Import native OS color scheme
|
||||||
try:
|
try:
|
||||||
def GreenColor():
|
def GreenColor():
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
GreenColor = (chr(27)+"[1;32m")
|
GreenColor = (chr(27)+"[1;32m")
|
||||||
print (GreenColor+"", end="")
|
print (GreenColor+"", end="")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.system("color 2")
|
os.system("color 2")
|
||||||
def RedColor():
|
def RedColor():
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
RedColor = (chr(27)+"[1;31m")
|
RedColor = (chr(27)+"[1;31m")
|
||||||
print (RedColor+"", end="")
|
print (RedColor+"", end="")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.system("color 4")
|
os.system("color 4")
|
||||||
def OrangeColor():
|
def OrangeColor():
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
OrangeColor = (chr(27)+"[1;33m")
|
OrangeColor = (chr(27)+"[1;33m")
|
||||||
print (OrangeColor+"", end="")
|
print (OrangeColor+"", end="")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.system("color 6")
|
os.system("color 6")
|
||||||
def EndColor():
|
def EndColor():
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
EndColor = (chr(27)+"[0m")
|
EndColor = (chr(27)+"[0m")
|
||||||
print (EndColor+"", end="")
|
print (EndColor+"", end="")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
print ("", end="")
|
print ("", end="")
|
||||||
except:
|
except:
|
||||||
print ("")
|
print ("")
|
||||||
print ("* Error importing native color scheme")
|
print ("* Error importing native color scheme")
|
||||||
print ("")
|
print ("")
|
||||||
PauseExit=input("+ Press ENTER to exit ")
|
PauseExit=input("+ Press ENTER to exit ")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
#Check if ip2e-daemon is running.
|
#Check if ip2e-daemon is running.
|
||||||
if os.path.isfile("ip2e.lock"):
|
if os.path.isfile("ip2e.lock"):
|
||||||
readLock=open('ip2e.lock', 'r')
|
readLock=open('ip2e.lock', 'r')
|
||||||
LockN=readLock.read()
|
LockN=readLock.read()
|
||||||
readLock.close()
|
readLock.close()
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
print ("Checking "+LockFile+"...")
|
print ("Checking "+LockFile+"...")
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
readLock2=open('ip2e.lock', 'r')
|
readLock2=open('ip2e.lock', 'r')
|
||||||
LockN2=readLock2.read()
|
LockN2=readLock2.read()
|
||||||
readLock2.close()
|
readLock2.close()
|
||||||
if LockN != LockN2:
|
if LockN != LockN2:
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
print ("")
|
print ("")
|
||||||
print ("* ip2e-daemon is already running.")
|
print ("* ip2e-daemon is already running.")
|
||||||
print ("")
|
print ("")
|
||||||
PauseExit=input("+ Press ENTER to exit ")
|
PauseExit=input("+ Press ENTER to exit ")
|
||||||
exit()
|
exit()
|
||||||
if not os.path.isfile("ip2e.lock"):
|
if not os.path.isfile("ip2e.lock"):
|
||||||
createLock=open('ip2e.lock','w')
|
createLock=open('ip2e.lock','w')
|
||||||
createLock.write(str(random.randrange(135790)))
|
createLock.write(str(random.randrange(135790)))
|
||||||
createLock.close()
|
createLock.close()
|
||||||
|
|
||||||
#Function to lock process.
|
#Function to lock process.
|
||||||
def LockProcess():
|
def LockProcess():
|
||||||
createLock=open('ip2e.lock','w')
|
createLock=open('ip2e.lock','w')
|
||||||
createLock.write(str(random.randrange(135790)))
|
createLock.write(str(random.randrange(135790)))
|
||||||
createLock.close()
|
createLock.close()
|
||||||
|
|
||||||
#Function to sleep 'N' seconds.
|
#Function to sleep 'N' seconds.
|
||||||
def TimeSleep(N):
|
def TimeSleep(N):
|
||||||
Time=1
|
Time=1
|
||||||
while Time < N:
|
while Time < N:
|
||||||
createLock=open('ip2e.lock','w')
|
createLock=open('ip2e.lock','w')
|
||||||
createLock.write(str(random.randrange(135790)))
|
createLock.write(str(random.randrange(135790)))
|
||||||
createLock.close()
|
createLock.close()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
Time=Time + 1
|
Time=Time + 1
|
||||||
|
|
||||||
#Check if exists a previous log.file
|
#Check if exists a previous log.file
|
||||||
if os.path.isfile("ip2e.log"):
|
if os.path.isfile("ip2e.log"):
|
||||||
createlog=open('ip2e.log','w')
|
createlog=open('ip2e.log','w')
|
||||||
createlog.close()
|
createlog.close()
|
||||||
|
|
||||||
#Run ip2e daemon
|
#Run ip2e daemon
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
|
@ -185,107 +185,107 @@ TimeSleep(60)
|
||||||
|
|
||||||
PublicIP = 1
|
PublicIP = 1
|
||||||
while PublicIP <= 2:
|
while PublicIP <= 2:
|
||||||
GetCurrentIP = 1
|
GetCurrentIP = 1
|
||||||
while GetCurrentIP <= 2:
|
while GetCurrentIP <= 2:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
LockProcess()
|
LockProcess()
|
||||||
OrangeColor()
|
OrangeColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] IP Updating...")
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog=open('ip2e.log','a')
|
editlog=open('ip2e.log','a')
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP Updating...\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP Updating...\n")
|
||||||
#Check & get the new IP
|
#Check & get the new IP
|
||||||
try:
|
try:
|
||||||
LockProcess()
|
LockProcess()
|
||||||
response = urllib.request.urlopen('http://icanhazip.com')
|
response = urllib.request.urlopen('http://icanhazip.com')
|
||||||
#response = urllib.request.urlopen('http://ip.appspot.com/')
|
#response = urllib.request.urlopen('http://ip.appspot.com/')
|
||||||
#response = urllib.request.urlopen('http://ident.me')
|
#response = urllib.request.urlopen('http://ident.me')
|
||||||
NewIPRaw = response.read()
|
NewIPRaw = response.read()
|
||||||
NewIP = NewIPRaw.strip().decode('utf-8')
|
NewIP = NewIPRaw.strip().decode('utf-8')
|
||||||
GetCurrentIP += 2
|
GetCurrentIP += 2
|
||||||
except:
|
except:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
LockProcess()
|
LockProcess()
|
||||||
RedColor()
|
RedColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Error getting IP")
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...")
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Error getting IP\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Error getting IP\n")
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...\n")
|
||||||
TimeSleep(10)
|
TimeSleep(10)
|
||||||
#Read IP log file & get the current IP
|
#Read IP log file & get the current IP
|
||||||
readfileIP=open('IP.log', 'r')
|
readfileIP=open('IP.log', 'r')
|
||||||
CurrentIPRaw=readfileIP.read()
|
CurrentIPRaw=readfileIP.read()
|
||||||
CurrentIP=CurrentIPRaw.strip()
|
CurrentIP=CurrentIPRaw.strip()
|
||||||
readfileIP.close()
|
readfileIP.close()
|
||||||
LockProcess()
|
LockProcess()
|
||||||
#Check if the IP has been renewed
|
#Check if the IP has been renewed
|
||||||
if CurrentIP == NewIP:
|
if CurrentIP == NewIP:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
LockProcess()
|
LockProcess()
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
|
print ("[ip2e-daemon] ["+CurrentTime+"] IP has not changed")
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP has not changed\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] IP has not changed\n")
|
||||||
else:
|
else:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
LockProcess()
|
LockProcess()
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
|
print ("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP)
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP+"\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] New IP - From "+CurrentIP+" to "+NewIP+"\n")
|
||||||
SendEmailOK = 1
|
SendEmailOK = 1
|
||||||
while SendEmailOK <= 2:
|
while SendEmailOK <= 2:
|
||||||
LockProcess()
|
LockProcess()
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
#Sending email using smtplib
|
#Sending email using smtplib
|
||||||
SmtpSubject = "[ip2e-daemon] ["+CurrentTime+"] IP has changed"
|
SmtpSubject = "[ip2e-daemon] ["+CurrentTime+"] IP has changed"
|
||||||
SmtpHeader = "From: "+FromEmail+"\n"+"To: "+ToEmail+"\n"+"Subject: "+SmtpSubject+"\n"
|
SmtpHeader = "From: "+FromEmail+"\n"+"To: "+ToEmail+"\n"+"Subject: "+SmtpSubject+"\n"
|
||||||
SmtpBodyMessage = SmtpHeader+"\n"+"[ip2e] New IP is "+NewIP+"\n\n"
|
SmtpBodyMessage = SmtpHeader+"\n"+"[ip2e] New IP is "+NewIP+"\n\n"
|
||||||
#Check sending errors
|
#Check sending errors
|
||||||
try:
|
try:
|
||||||
server = smtplib.SMTP(SmtpFromEmail)
|
server = smtplib.SMTP(SmtpFromEmail)
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.starttls()
|
server.starttls()
|
||||||
server.ehlo()
|
server.ehlo()
|
||||||
server.login(FromEmailUser,FromEmailPass)
|
server.login(FromEmailUser,FromEmailPass)
|
||||||
server.sendmail(FromEmail, ToEmail, SmtpBodyMessage)
|
server.sendmail(FromEmail, ToEmail, SmtpBodyMessage)
|
||||||
server.quit()
|
server.quit()
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Email was sent successfully"
|
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Email was sent successfully"
|
||||||
LockProcess()
|
LockProcess()
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print (MailMessage+" ("+ToEmail+")")
|
print (MailMessage+" ("+ToEmail+")")
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog.write(MailMessage+" ("+ToEmail+")\n")
|
editlog.write(MailMessage+" ("+ToEmail+")\n")
|
||||||
SendEmailOK += 2
|
SendEmailOK += 2
|
||||||
except:
|
except:
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
LockProcess()
|
LockProcess()
|
||||||
RedColor()
|
RedColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Check your settings or your connection")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Check your settings or your connection")
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")\n")
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Check your settings or your connection\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Check your settings or your connection\n")
|
||||||
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Failed to send email"
|
MailMessage="[ip2e-daemon] ["+CurrentTime+"] Failed to send email"
|
||||||
RedColor()
|
RedColor()
|
||||||
print (MailMessage+" ("+ToEmail+")")
|
print (MailMessage+" ("+ToEmail+")")
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...")
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog.write(MailMessage+" ("+ToEmail+")\n")
|
editlog.write(MailMessage+" ("+ToEmail+")\n")
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Retrying in 10 seconds...\n")
|
||||||
TimeSleep(10)
|
TimeSleep(10)
|
||||||
#Remove the previous IP log file & create a new.
|
#Remove the previous IP log file & create a new.
|
||||||
ip2eIPcf=open('IP.log','w')
|
ip2eIPcf=open('IP.log','w')
|
||||||
ip2eIPcf.write(NewIP)
|
ip2eIPcf.write(NewIP)
|
||||||
ip2eIPcf.close()
|
ip2eIPcf.close()
|
||||||
#Wait 10 minutes until the next checking
|
#Wait 10 minutes until the next checking
|
||||||
CurrentTime = time.strftime("%H:%M")
|
CurrentTime = time.strftime("%H:%M")
|
||||||
LockProcess()
|
LockProcess()
|
||||||
GreenColor()
|
GreenColor()
|
||||||
print ("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
|
print ("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...")
|
||||||
EndColor()
|
EndColor()
|
||||||
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...\n")
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Next update in 10 minutes...\n")
|
||||||
editlog.close()
|
editlog.close()
|
||||||
TimeSleep(600)
|
TimeSleep(600)
|
||||||
|
|
66
ip2e-log.py
66
ip2e-log.py
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
# ip2e (IP to email) - See the log file. |
|
# ip2e (IP to email) - See the log file. |
|
||||||
# Created by q3aql (q3aql@openmailbox.org) |
|
# Created by q3aql (q3aql@protonmail.ch) |
|
||||||
# Licensed by GPL v.3 |
|
# Licensed by GPL v.3 |
|
||||||
# Last update: 01-03-2016 |
|
# Last update: 03-04-2021 |
|
||||||
# |
|
# |
|
||||||
# Compatible with Python 3.x |
|
# Compatible with Python 3.x |
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
|
@ -17,49 +17,49 @@ import sys
|
||||||
|
|
||||||
#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):
|
||||||
print ("")
|
print ("")
|
||||||
print ("You need python 3.x to run this program.")
|
print ("You need python 3.x to run this program.")
|
||||||
print ("")
|
print ("")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
#Function to clear screen
|
#Function to clear screen
|
||||||
def ClearScreen():
|
def ClearScreen():
|
||||||
if sys.platform == "cygwin":
|
if sys.platform == "cygwin":
|
||||||
print (300 * "\n")
|
print (300 * "\n")
|
||||||
elif os.name == "posix":
|
elif os.name == "posix":
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.system("cls")
|
os.system("cls")
|
||||||
else:
|
else:
|
||||||
print ("Error: Unable clear screen")
|
print ("* Error: Unable clear screen")
|
||||||
|
|
||||||
#Detect system & PATH of user folder
|
#Detect system & PATH of user folder
|
||||||
if os.path.exists("/storage/sdcard0"):
|
if os.path.exists("/storage/sdcard0"):
|
||||||
HOMESCARD0="/storage/sdcard0/Android/data"
|
HOMESCARD0="/storage/sdcard0/Android/data"
|
||||||
os.chdir(HOMESCARD0)
|
os.chdir(HOMESCARD0)
|
||||||
print ("Android (Posix) detected")
|
print ("Android (Posix) detected")
|
||||||
elif os.name == "posix":
|
elif os.name == "posix":
|
||||||
os.chdir(os.environ["HOME"])
|
os.chdir(os.environ["HOME"])
|
||||||
print ("Unix (Posix) detected")
|
print ("Unix (Posix) detected")
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
os.chdir(os.environ["USERPROFILE"])
|
os.chdir(os.environ["USERPROFILE"])
|
||||||
print ("Windows detected")
|
print ("Windows detected")
|
||||||
|
|
||||||
if not os.path.exists(".ip2e"):
|
if not os.path.exists(".ip2e"):
|
||||||
os.makedirs(".ip2e")
|
os.makedirs(".ip2e")
|
||||||
os.chdir(".ip2e")
|
os.chdir(".ip2e")
|
||||||
if os.path.exists(".ip2e"):
|
if os.path.exists(".ip2e"):
|
||||||
os.chdir(".ip2e")
|
os.chdir(".ip2e")
|
||||||
|
|
||||||
#See the log file
|
#See the log file
|
||||||
if os.path.isfile("ip2e.log"):
|
if os.path.isfile("ip2e.log"):
|
||||||
print ("ip2e.log exists")
|
print ("ip2e.log exists")
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
readfile=open('ip2e.log', 'r')
|
readfile=open('ip2e.log', 'r')
|
||||||
print(readfile.read())
|
print(readfile.read())
|
||||||
readfile.close()
|
readfile.close()
|
||||||
else:
|
else:
|
||||||
ClearScreen()
|
ClearScreen()
|
||||||
print ("")
|
print ("")
|
||||||
print ("* ip2e.log doesn't exist.")
|
print ("* ip2e.log doesn't exist.")
|
||||||
print ("")
|
print ("")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user