emails from command prompt.
Doug Stewart
doug.dastew at gmail.com
Thu Jun 15 16:29:01 UTC 2017
>
>
> Thanks for the all the help.
>
I have some python code and a bash script to run it, and it works great.
My overall project was to see when my wan address changes and email me the
new wan IP address.
this allows me to ssh in or vnc in when traveling. I only have a dynamic
ip address.
this code will run ever 10 min. at home and does not involve the internet
until my IP changes.
#!/bin/bash
python dougsendmailpython3.py
___________________________________________________________
import smtplib
import subprocess
#import os, sys
p=subprocess.Popen("curl ipinfo.io/ip", shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
p.stdout.readline()
p.stdout.readline()
p.stdout.readline()
q=p.stdout.readline()
print "Current IP = "+ q
file = open("wanipadds.txt", "r")
oldip = file.read()
file.close()
print "now for oldip = " + oldip
if oldip != q :
print "New IP found!!! "
file = open("wanipadds.txt", "w")
file.write(q)
file.close()
from email.MIMEMultipart import MIMEMultipart
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("doug.dastew at gmail.com", "password")
SUBJECT = " IP Address is = "+ q
msg = MIMEMultipart()
msg['Subject'] = SUBJECT
server.sendmail("doug.dastew at gmail.com", "doug.dastew at gmail.com",
msg.as_string())
server.quit()
__________________________________________________
My email looks like this
IP Address is = 70.54.94.9
Thanks again and if anyone wants this code it is free!!!!!
--
DAS[image: Certificate for 206392]
<https://linuxcounter.net/user/206392.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-ca/attachments/20170615/a42b5d86/attachment.html>
More information about the ubuntu-ca
mailing list