zoukankan      html  css  js  c++  java
  • 判断IP是否是IPV4

    bool isVaildIp(const char *ip)
    {
    	int dots = 0; /*字符.的个数*/
    	int setions = 0; /*ip每一部分总和(0-255)*/ 
    
    	if (NULL == ip || *ip == '.') { /*排除输入参数为NULL, 或者一个字符为'.'的字符串*/ 
    		return false;
    	}   
    
    	while (*ip) {
    
    		if (*ip == '.') {
    			dots ++; 
    			if (setions >= 0 && setions <= 255) { /*检查ip是否合法*/
    				setions = 0;
    				ip++;
    				continue;
    			}   
    			return false;
    		}   
    		else if (*ip >= '0' && *ip <= '9') { /*判断是不是数字*/
    			setions = setions * 10 + (*ip - '0'); /*求每一段总和*/
    		} else 
    			return false;
    		ip++;   
    	}   
    
    	if (setions >= 0 && setions <= 255) {
    		if (dots == 3) {
    			return true;
    		}   
    	}   
    
    	return false;
    }
    

      

  • 相关阅读:
    图像按钮
    提交按钮
    文件上传域
    Python创建虚拟环境
    Typecho使用技巧
    面向对象
    Python语法入门
    Python 基础数据类型
    与用户交互
    MySQL5.7安装教程
  • 原文地址:https://www.cnblogs.com/porkerface/p/12340840.html
Copyright © 2011-2022 走看看