zoukankan      html  css  js  c++  java
  • ipv4的两种验证方法

    import re
    def check_ip4_1(ip):
        result=[]
        if ip.count(".")==3:
            for i in ip.split("."):
                try:
                    if i.strip().startswith("0"):
                        result.append(1)
                    elif int(i.strip())>=1 and int(i.strip())<=255:
                        result.append(2)
                except Exception,e:
                    print "error",e.message
            if result.count(2)==4:
                return "True"
            else:
                return "False"
     
    def check_ip4_2(ip):
        rule1=re.compile(r"[1-2][0-9][0-9]")
        rule2=re.compile(r"[1-9][1-9]")
        rule3=re.compile(r"[1-9]")
        result=[]
        if ip.count(".")==3:
            for i in ip.split("."):
                try:
                    if i.strip().startswith("0"):
                        result.append(1)
                    elif rule1.match(i) or rule2.match(i) or rule3.match(i):
                        result.append(2)
                except Exception,e:
                    print "error",e.message
            if result.count(2)==4:
                return "True"
            else:
                return "False"
     
    if __name__=="__message__":
        check_ip4_1(ip4)
        check_ip4_2(ip4)
  • 相关阅读:
    OpenCV中 常用 函数 的作用
    OpenCV中Mat的使用
    awk --- 常用技巧
    Specify 的含义 ------ 转载
    关于CPU CACHE工作机制的学习
    关于CPU Cache -- 程序猿需要知道的那些事
    ARM920T的Cache
    Learn Git and GitHub
    朴素贝叶斯分类器(MNIST数据集)
    k-近邻算法(KNN)识别手写数字
  • 原文地址:https://www.cnblogs.com/zhangtebie/p/11185896.html
Copyright © 2011-2022 走看看