把如下代码加入到<head>区域中
<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("235.12") >= -1)
// 这是想要禁止访问的IP例如: 235.12.xxx.xxx
{
alert("You are not permitted to access this site.");
history.go(-1);
}
}
// End -->
</script>
禁用特定IP访问网站
本文介绍了一段JavaScript代码,该代码可以在Netscape Navigator 4浏览器中检测并阻止特定IP地址(如235.12.xxx.xxx)的用户访问网站。当检测到禁止的IP地址时,会弹出警告消息并使浏览器返回上一页。
4372





