getmyip.py con.list

      有的没的 2015-4-10 1:47:00

 import re

import urllib2
import os
 
 
class Getmyip:
 
    def getip(self):
        try:
            myip = self.visit("http://1111.ip138.com/ic.asp")
            #myip = self.visit("http://ip.chinaz.com")
            #myip = self.visit("http://ip.lockview.cn")
            #myip = self.visit("http://ip.cn")
            return myip
        except:
            myip = self.visit("http://www.133ip.com")
            return myip
 
    def visit(self, url):
        opener = urllib2.urlopen(url)
        if url == opener.geturl():
            str = opener.read()
            strip = re.compile(r'\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b', re.IGNORECASE)
            return re.search(strip, str).group(0)
 
getmyip = Getmyip()
localip = getmyip.getip()
print localip
#os.system("echo '%s' | mail -s 'Home Public Ip :'@163.com" % localip)
 
 
cron.list
 
0   */4   *   *   *   python /home/joy/getmyip.py
 
 
标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}