Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
510
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. to = 'alt.mail.16@gmail.com'
  11. gmail_user = 'alt.mail.16@gmail.com'
  12. gmail_password = 'Snake_%534%'
  13. smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
  14. smtpserver.ehlo()
  15. smtpserver.starttls()
  16. smtpserver.ehlo
  17. smtpserver.login(gmail_user, gmail_password)
  18. today = datetime.date.today()
  19. # Very Linux Specific
  20. ipaddr = socket.gethostbyname(socket.gethostname())
  21. extipaddr = urllib2.urlopen("http://icanhazip.com").read()
  22. my_ip = 'Local address: %s\nExternal address: %s' % (ipaddr, extipaddr)
  23. msg = MIMEText(my_ip)
  24. msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
  25. msg['From'] = gmail_user
  26. msg['To'] = to
  27. smtpserver.sendmail(gmail_user, [to], msg.as_string())
  28. smtpserver.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement