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)
  • 相关阅读:
    eclipse的下载安装
    找不到符号 类string
    [转]Android_开源框架_AndroidUniversalImageLoader网络图片加载
    [转]移动web开发经验总结
    测试一下吧
    javascript 的 encodeURIComponent 函数用 Objective-C 实现
    几个Objective-C的HTML解析库
    html test
    一段测试代码
    [转]Embed WebView in Fragment
  • 原文地址:https://www.cnblogs.com/zhangtebie/p/11185896.html
Copyright © 2011-2022 走看看