The following small series for everyone to bring a python to obtain the external IP concurrent Mail implementation method. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
Step One: crawl the extranet IP via ip138
The second step: through the Python smtplib module and email to send mail, specific use to search online,
The following is a code example:
#!/usr/bin/env python#coding:utf-8 Import urllib2import reimport smtplibfrom email. Mimetext Import mimetextfrom Email. Header Import Header ########################################## #get IP addressurl = "http://1212.ip138.com/ic.asp" url _op = Urllib2.urlopen (URL) url_content = Url_op.read () ip_content = Re.findall (R ' \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} ', url_content) Ipcode = ". Join (ip_content) ################################################## Setting Mail-server, Etcmail_host= "smtp.sina.com" mail_user= "Ckl" mail_pass= "woxxxx" mail_postfix= "Sina.com" ########################## ###################### #def Send_mail (to_list, Sub, content): me = Mail_user + "<" + Mail_user + "@" + Mail_postfix + "& gt; "msg = mimetext (content) msg[' Subject ') = Sub msg[' from ') = Me-msg[' to '] ="; ". Join (to_list) try:s = Smtplib. SMTP () s.connect (mail_host) s.login (Mail_user, Mail_pass) S.sendmail (Me, To_list, msg.as_string ()) S.close () return T Rue except Exception, E:print str (e) return False ################################################## Main processif __name__ = = "__main__": mailto_list=["41145XXXX@qq.com"] if Send_ Mail (mailto_list, "Your latest IP address", Ipcode): print "Send success!" else:print "Send failed!"