Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PyYoshi/974018 to your computer and use it in GitHub Desktop.
Save PyYoshi/974018 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
from email.MIMEText import MIMEText
from email.Utils import formatdate
import smtplib
import datetime
#LOGファイル
IP_LOG_FILE = "ip.log"
TIME_LOG_FILE = "time.log"
#IPチェックサービス
IP_URL = "http://ieserver.net/ipcheck.shtml"
#IP変更に関係なくメールを送信する
EVERY_SEND = False
#メール件名
MAIL_SUBJECT = "Send IP Address"
#送信先メールアドレス
TO_MAIL_ADDRESS = "hoge@gmail.com"
#送信元メールアドレス
FROM_MAIL_ADDRESS = "hoge@gmail.com"
#Googleアカウント
ID = "hoge"
PASS = "fuga"
def getIP():
ip = urllib2.urlopen(IP_URL).read()
fp = open(IP_LOG_FILE, 'w')
fp.write(ip)
return ip
def getTime():
d = datetime.datetime.today()
#d.strftime('%Y%m%d%H%M%S')
print d.strftime('%Y%m%d%H%M%S')[9:]
def chkIP():
fp = open(IP_LOG_FILE, 'r')
ip = fp.read()
return ip
def sendMail(nowIP):
msg_tmp = nowIP
msg = MIMEText(msg_tmp)
msg['Subject'] = MAIL_SUBJECT
msg['From'] = FROM_MAIL_ADDRESS
msg['To'] = TO_MAIL_ADDRESS
msg['Date'] = formatdate()
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(ID, PASS)
s.sendmail(FROM_MAIL_ADDRESS, [TO_MAIL_ADDRESS], msg.as_string())
s.close()
def main():
#nowIP = getIP()
getTime()
#sendMail(nowIP)
#chkIP()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment