Skip to content

Commit

Permalink
Adding handling of failing DNS lookups, so script doesn't exit
Browse files Browse the repository at this point in the history
  • Loading branch information
morphex committed Sep 20, 2018
1 parent 8c8b84f commit a02dbc0
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions surveil.py
Expand Up @@ -79,16 +79,23 @@ def message(filename):
subtype=imghdr.what(None, data))

domain = sys.argv[1].split('@')[-1]
for MX in DNS.mxlookup(domain):
host = MX[1]
while 1:
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
print("Sent email")
break
except:
pass
for MX in DNS.mxlookup(domain):
host = MX[1]
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
print("Sent email")
return
except:
pass
break
except Exception:
print("Error sending mail: ")
print(sys.exc_info())
time.sleep(5) # So we don't spam the system

def message_video(directory):
msg = EmailMessage()
Expand All @@ -107,21 +114,24 @@ def message_video(directory):
subtype='plain', filename='out.log.txt')

domain = sys.argv[1].split('@')[-1]
for MX in DNS.mxlookup(domain):
host = MX[1]
while 1:
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
#os.unlink(directory + "/done.txt")
os.system("rm %s/*" % directory)
print("Sent email")
break
except:
pass



for MX in DNS.mxlookup(domain):
host = MX[1]
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
os.system("rm %s/*" % directory)
print("Sent email")
return
except:
pass
except Exception:
print("Error sending mail: ")
print(sys.exc_info())
time.sleep(5) # So we don't spam the system

def setup_video():
valid_files = []
for file in glob.glob('images/*.jpg'):
Expand Down

0 comments on commit a02dbc0

Please sign in to comment.