苏戴斯诵读古兰经114章:如何禁止某个ip/ip段访问网站页面

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 14:53:09
当前全部家当,就30了………………

要求js写的代码…
网上copy到一段,但是似乎没有用,代码如下:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
netscape = (navigator.appName.indexOf("Netscape") != -1);
version4 = (navigator.appVersion.indexOf("4.") != -1);
if (netscape && version4) {
ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();
if (ip.indexOf("60.55") >= -1)
// 这是想要禁止访问的IP例如: 60.55.xxx.xxx
{
alert("You are not permitted to access this site.");
history.go(-1);
}
}
// End -->
</script>
谁有可用的能共享下吗,…不胜(感激)涕零

if (ip.indexOf("60.55") >= -1)
这句有问题
indexof方法是返回所找字符串的所在的位置,如果没有则返回-1
应该改为
if (ip.indexOf("60.55") != -1) 或者if (ip.indexOf("60.55") > -1)
或者if (ip.indexOf("60.55") ==0)
第三个比较准确一点