共计 397 个字符,预计需要花费 1 分钟才能阅读完成。
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 userIP
这个用js实现的方法,也是网上找来的:
用JS不错,因为JS 获取的 IP 有个长处就是他获取的是本机配置的 IP,假如电脑通过局域网上网,那么他获得的就是电脑的局域网 IP,而不像 ASP 中 Request 获取的是电脑连接到互连网的 IP。
[html]
[/html]
据说在使用中可能会出现警告,但是这只是测试,应该不碍事的
又一个校园网的例子:
[html]
<%dim userip,ipk,gotourlipuserip=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 IfResponse.Redirect "eorr.htm" 其他用户,则导向出错页面%>
[/html]