Python implements a method for acquiring external IP concurrent messages

Source: Internet
Author: User
Tags get ip
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!"
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.