asp中实现根据内网和外网用户IP进行页面跳转

asp判断客户端处于内网还是外网进行页面重定向:
这段时间上校园网,发现页面变的简单了,但是在校园网上打开时还是原来的主页面,于是知道这个是添加了一段关于内网和外网访客ip的判断。网上搜索了一下相关实现方法,找到下面这个比较不错的:

<% function IP2Num(sip) dim str1,str2,str3,str4 dim num IP2Num=0 if isnumeric(left(sip,2)) then str1=left(sip,instr(sip,".")-1) sip=mid(sip,instr(sip,".")+1) str2=left(sip,instr(sip,".")-1) sip=mid(sip,instr(sip,".")+1) str3=left(sip,instr(sip,".")-1) str4=mid(sip,instr(sip,".")+1) num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1 IP2Num = num end if end function userIP = IP2Num(Request.ServerVariables("REMOTE_ADDR")) if (userIP>Ip2Num("192.168.0.0") and userIPIp2Num("127.0.0.0") and userIPIp2Num("10.0.0.0") and userIP

这个用js实现的方法,也是网上找来的:
用JS不错,因为JS 获取的 IP 有个长处就是他获取的是本机配置的 IP,假如电脑通过局域网上网,那么他获得的就是电脑的局域网 IP,而不像 ASP 中 Request 获取的是电脑连接到互连网的 IP。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JS获取客户端IP</title>
</head>
<body>
<script type="text/javascript" language="javascript">
<!--
function GetLocalIPAddress()
{
    var obj = null;
    var rslt = "";
    try
    {
        obj = new ActiveXObject("rcbdyctl.Setting");
        rslt = obj.GetIPAddress;
        obj = null;
    }
    catch(e)
    {
        //异常发生
    }    
    return rslt;
}
document.write("您的IP是:" + GetLocalIPAddress());
//-->
</script>
</body>
</html>

据说在使用中可能会出现警告,但是这只是测试,应该不碍事的

又一个校园网的例子:

<html>
<head>
<title>网页自动转向-志文工作室</title>
</head>
<body>
<%
dim userip,ipk,gotourlip
userip=Request.ServerVariables("REMOTE_ADDR")
ipk=split(userip,".",-1,1)
gotourlip=ipk(0)&"."&ipk(1)
if gotourlip="10.10" Then 如果是校内用户
Response.Redirect "http://" 导向到校内的地址
Elseif gotourlip="172.16" then 如果是外网用户
Response.Redirect "http://10.10.2.250" 导向到教育网内的地址
end If
Response.Redirect "eorr.htm" 其他用户,则导向出错页面
%>
</body>
</html>
点赞 (0)

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code