Created
October 23, 2015 18:26
-
-
Save adoyle/a31094adabc123ff4cf5 to your computer and use it in GitHub Desktop.
Meant to be run on a Raspberry Pi to email the current IP address to yourself. Note that this uses unauthenticated SMTP and only works in certain circumstances. This lets you run a headless pi that you can ssh in to.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import subprocess | |
my_email = 'myemail@gmail.com' | |
to_email = 'myemail@gmail.com' | |
myip = subprocess.check_output(['hostname', '-I']) | |
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n") % (my_email, to_email, "IP from the Pi") | |
msg = msg + "MY IP is " + myip | |
s = smtplib.SMTP('outgoing.mit.edu') | |
s.sendmail(my_email, [to_email], msg) | |
s.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment