网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 asp实现检查ip地址是否为内网或者私有ip地址的代码分享
内容
    asp检查ip地址是否为私有/内网ip地址源代码。
    内网/私有IP地址网段如下,还有127开头的回环地址:
    10.0.0.0-10.255.255.255
    172.16.0.0—172.31.255.255
    192.168.0.0-192.168.255.255
    实现代码:
    01 <%
    02 function IpToNumber(ip)'IP地址转为数字
    03 arr=split(ip,".")
    04 IpToNumber=256*256*256*clng(arr(0))+256*256*clng(arr(1))+256*clng(arr(2))+clng(arr(3))
    05 end function
    06 function IsPrivateIp(ip)'判断给定的IP地址是否内网/私有ip地址
    07 if instr(ip,"127.")=1 then'回环IP地址
    08 IsPrivateIp=true:exit function
    09 end if
    10 ABegin=IpToNumber("10.0.0.0"):AEnd=IpToNumber("10.255.255.255")'A类私有IP地址
    11 BBegin=IpToNumber("172.16.0.0"):BEnd=IpToNumber("172.31.255.255")'B类私有IP地址
    12 CBegin=IpToNumber("192.168.0.0"):CEnd=IpToNumber("192.168.255.255")'C类私有IP地址
    13 IpNum=IpToNumber(ip)
    14 IsPrivateIp=(ABegin<=IpNum and IpNum<=AEnd) or (BBegin<=IpNum and IpNum<=BEnd) or (CBegin<=IpNum and IpNum<=CEnd)
    15 end function
    16 Response.Write IsPrivateIp("11.255.255.255")&"<br>"'false
    17 Response.Write IsPrivateIp("182.255.255.255")&"<br>"'false
    18 Response.Write IsPrivateIp("172.30.255.255")&"<br>"'true
    19 Response.Write IsPrivateIp("192.168.205.2")&"<br>"'true
    20 Response.Write IsPrivateIp("127.168.205.2")'true
    21 %>
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/16 8:44:39