Skip to content

Instantly share code, notes, and snippets.

@adoyle
Created October 23, 2015 18:26
Show Gist options
  • Save adoyle/a31094adabc123ff4cf5 to your computer and use it in GitHub Desktop.
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.
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