2015/04/10 | getmyip.py con.list
类别(有的没的) | 评论(0) | 阅读(176) | 发表于 01:47

 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
 
 
0

评论Comments

日志分类
首页[193]
flash As[107]
有的没的[59]
数码照片[4]
自由世界[19]
blender[4]