小光网络技术博客

介绍和研究搜索引擎优化、SEO、asp、asp.net、php、jsp技术

« AJAX实现4级联动菜单PHP读取一个文件夹内有多少个文件的函数. »

asp判断IP地址是否合法

如果你想做一个IP查询那么你就要先判断这个IP地址是否合法,下法写一个这样的函数来判断是否合法.
<%  

      function   chk_ip(strIP)  

        dim   boolIsIP          

        dim   arrIP  

        boolIsIP=true         '函数初始值为true  

        arrIP=split(strIP,".")     '将输入的IP用"."分割为数组,数组下标从0开始,所以有效IP分割后的数组上界必须为3  

        if   ubound(arrIP)<>3   then  

            boolIsIP=false      

        else  

            for   intLoop=0   to   Ubound(arrIP)  

        if   not   isnumeric(arrIP(intLoop))   then     '检查数组元素中各项是否为数字,如果不是则不是有效IP  

            boolIsIP=false  

                else  

            if   arrIP(intLoop)>255   or   arrIP(intLoop)<0   then   '检查IP数字是否满足IP的取值范围  

        boolIsIP=false  

    end   if  

        end   if  

    next  

        end   if  

        chk_ip=boolIsIp  

      end   function  

  %> 


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Sam

Copyright 2007-2008 小光. Some Rights Reserved.