I need the IP address of my Raspberry Pi so that I can SSH into it. This must be possible to do at my university without a monitor connected. So I made a Python script which sends me the IP address by email, but I can't get it to run at boot. I tried adding
to the end of
/home/pi/.bashrc but I couldn't get it to work. Does anyone know how to get this to work? Or another way to get the IP?
I have a Raspberry Pi 2 model B running Raspbian.
The Python script:
import smtplib from email.mime.text import MIMEText import datetime import subprocess ip = subprocess.check_output(['hostname', '-I']) to = 'My email address' gmail_user = 'Gmail used to send from' gmail_password = 'Password' smtpserver = smtplib.SMTP('smtp.gmail.com', 587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo() smtpserver.login(gmail_user, gmail_password) today = datetime.date.today() my_msg = '%s' % today.strftime('%b %d %Y') msg = MIMEText(my_msg) msg['Subject'] = 'Raspberry Pi IP: %s' % ip[:-2].decode("UTF-8") msg['From'] = gmail_user msg['To'] = to smtpserver.sendmail(gmail_user, [to], msg.as_string()) smtpserver.quit()