Guest User

Untitled

a guest
Jun 7th, 2017
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # modified from http://elinux.org/RPi_Email_IP_On_Boot_Debian
  3. import subprocess
  4. import smtplib
  5. import socket
  6. from email.mime.text import MIMEText
  7. import datetime
  8. import urllib2
  9. # Change to your own account information
  10. gmail_user = '[email protected]'
  11. gmail_password = 'Snake_%534%'
  12. smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
  13. smtpserver.ehlo()
  14. smtpserver.starttls()
  15. smtpserver.ehlo
  16. smtpserver.login(gmail_user, gmail_password)
  17. today = datetime.date.today()
  18. # Very Linux Specific
  19. ipaddr = socket.gethostbyname(socket.gethostname())
  20. extipaddr = urllib2.urlopen("http://icanhazip.com").read()
  21. my_ip = 'Local address: %s\nExternal address: %s' % (ipaddr, extipaddr)
  22. msg = MIMEText(my_ip)
  23. msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
  24. msg['From'] = gmail_user
  25. msg['To'] = to
  26. smtpserver.sendmail(gmail_user, [to], msg.as_string())
  27. smtpserver.quit()
Advertisement
Add Comment
Please, Sign In to add comment