Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
1,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import subprocess
  4. import smtplib
  5. from email.mime.text import MIMEText
  6. import datetime
  7.  
  8. # Change to your own account information
  9. to = 'me@example.com'
  10. gmail_user = 'test@gmail.com'
  11. gmail_password = 'yourpassword'
  12. today = datetime.date.today()
  13.  
  14. smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
  15. smtpserver.ehlo()
  16. smtpserver.starttls()
  17. smtpserver.ehlo
  18. smtpserver.login(gmail_user, gmail_password)
  19.  
  20.  
  21. arg = 'ip route list'
  22. p = subprocess.Popen(arg, shell=True, stdout=subprocess.PIPE)
  23. data = p.communicate()
  24. split_data = data[0].split()
  25. ipaddr = split_data[split_data.index('src') + 1]
  26. my_ip = 'Your ip is %s' % ipaddr
  27. msg = MIMEText(my_ip)
  28. msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
  29. msg['From'] = gmail_user
  30. msg['To'] = to
  31. smtpserver.sendmail(gmail_user, [to], msg.as_string())
  32. smtpserver.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement