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)
  • 相关阅读:
    Mysql基本操作
    MySql架构
    并发中关键字的语义
    SpringMVC<一> 基本结构与配置
    Tomcat 顶层结构
    Linux 日常常用指令
    JSON 数据格式
    RMAN 增量备份级别说明
    Oracle常用数据库系统表单以及SQL的整理
    使用puTTY或Xshell连接阿里云TimeOut超时
  • 原文地址:https://www.cnblogs.com/zhangtebie/p/11185896.html
Copyright © 2011-2022 走看看