-
-
Save nibocn/06ab864530693bdc5222 to your computer and use it in GitHub Desktop.
Revisions
-
MikeZhang revised this gist
Nov 15, 2012 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,23 +14,25 @@ def getPublicIp(): return re.search('\d+\.\d+\.\d+\.\d+',urllib2.urlopen("http://www.whereismyip.com").read()).group(0) def getMailContent(publicIp): msg2Snd = "From: <" + sender + ">\n" msg2Snd += "To: <" + receivers[0] + ">\n" msg2Snd += "Subject: ipReport\n\n" msg2Snd += "private IP : " + re.search("\d+\.\d+\.\d+\.\d+",Popen("ifconfig", stdout=PIPE).stdout.read()).group(0) + "\n" msg2Snd += "public IP : " + publicIp + "\n" return msg2Snd while True: try: publicIp = getPublicIp() if publicIp==socket.gethostbyname('XXXX.oicp.net'): time.sleep(checkTime) continue smtpObj = smtplib.SMTP(smtpServer,smtpPort) smtpObj.ehlo() smtpObj.login(sender,senderPasswd) smtpObj.sendmail(sender, receivers, getMailContent(publicIp)) print "Successfully sent email" except : print "Error: unable to send email" time.sleep(checkTime) -
MikeZhang revised this gist
Nov 15, 2012 . No changes.There are no files selected for viewing
-
MikeZhang created this gist
Nov 15, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/usr/bin/python import smtplib,re,urllib2,time import socket from subprocess import Popen, PIPE smtpServer='smtp.163.com' smtpPort='25' sender = 'XXXXX@163.com' senderPasswd = "XXXXX" receivers = ['XXXXX@gmail.com'] checkTime = 60 * 10 # seconds def getPublicIp(): return re.search('\d+\.\d+\.\d+\.\d+',urllib2.urlopen("http://www.whereismyip.com").read()).group(0) def getMailContent(): msg2Snd = "From: <" + sender + ">\n" msg2Snd += "To: <" + receivers[0] + ">\n" msg2Snd += "Subject: ipReport\n\n" msg2Snd += "private IP : " + re.search("\d+\.\d+\.\d+\.\d+",Popen("ifconfig", stdout=PIPE).stdout.read()).group(0) + "\n" msg2Snd += "public IP : " + getPublicIp() + "\n" return msg2Snd while True: try: if getPublicIp() == socket.gethostbyname('XXXXX.oicp.net'): time.sleep(checkTime) continue smtpObj = smtplib.SMTP(smtpServer,smtpPort) smtpObj.ehlo() smtpObj.login(sender,senderPasswd) smtpObj.sendmail(sender, receivers, getMailContent()) print "Successfully sent email" except : print "Error: unable to send email"