Guest User

Untitled

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