Guest User

Untitled

a guest
Sep 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. # Email IP addresses
  2.  
  3. import os
  4. import sys
  5. import smtplib
  6.  
  7. # CONSTANTS:
  8. storage_dir = os.path.dirname(os.path.realpath(__file__))
  9. message = 'Network Change detected:\n'
  10.  
  11. # AUTOSET:
  12. ipv4 = ""
  13. ipv6 = ""
  14.  
  15. # SCRIPT:
  16. os.chdir(storage_dir) #Move to folder
  17. try:
  18. with open('ip_addr', 'r') as ipfile: # Open file if it exists
  19. ips = ipfile.read().splitlines() # Read into array
  20. except IOError:
  21. print "Could not find IP address"
  22. sys.exit(1)
  23.  
  24. ipv4 = ips[0] #Store
  25. ipv6 = ips[1]
  26.  
  27. print "The ipv4 address is:", ipv4
  28. print "The ipv6 address is:", ipv6
  29. msg = str(message + ipv4 + '\n\n' + ipv6)
  30.  
  31. fromaddr = 'user_name@mail.com'
  32. toaddrs = 'to_user@mail.com'
  33. username = 'gmail_username@gmail.com'
  34. password = 'gmail_password'
  35. server = smtplib.SMTP('smtp.gmail.com:587') # Mail
  36. server.ehlo()
  37. server.starttls()
  38. server.login(username,password)
  39. server.sendmail(fromaddr, toaddrs, msg)
  40. server.quit()
Add Comment
Please, Sign In to add comment