Forum Moderators: phranque

Message Too Old, No Replies

Deny by IP

without using htaccess

         

ganderla

5:14 pm on Jan 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a way to deny a range of IP addresses without using htaccess file?
Maybe java or something?

Herath

5:47 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



Yes, there are several ways.

1) Use javascript.
<SCRIPT>
var ip = new java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip);
if (ipStr=='some ip') redirect the page.
</SCRIPT>

2) Use JSP
String IP = request.getRemoteHost();
if (IP=='some ip') redirect the page.

3) Use ASP (Similar to JSP method)

ganderla

5:58 pm on Jan 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I will use the first one,
Can I send that particular IP to a certain page?

Herath

6:03 pm on Jan 8, 2004 (gmt 0)

10+ Year Member



Yes.

if (ip == 'some ip') location.replace("some url");

ganderla

6:12 pm on Jan 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am sorry, I am getting an error
This is my code:

<SCRIPT language="JavaScript">
var ip = new java.net.InetAddress.getLocalHost();
var ipStr = new java.lang.String(ip);
if (ipStr=='***.**.***.***') location.replace("http://www.someurl.com");
</SCRIPT>

I appreciate this

keyplyr

6:56 am on Jan 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This will deny access, give them a "banned" alert message and send them back to the last page they came from:

<script type="text/javascript">
netscape = (navigator.appName.indexOf("Netscape")!= -1);
version4 = (navigator.appVersion.indexOf("4.")!= -1);

if (netscape && version4) {
ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();
if (ip.indexOf("XXX.XX.XXX.XXX") >= -1)

{
alert("You have been banned from this website!");
history.go(-1);
}
}
</script>

caio

6:09 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



Hi! How would you rewrite the code to let only one (or a range) of IP's to view the website and ban everyone else?

jomaxx

6:21 pm on Jan 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that a Javascript ban is easily circumvented. You might get lucky and the one person you're banning doesn't know to get around it, but it would certainly not be effective for keeping the world away from a private site.

caio

8:18 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



I agree... but if you combine that with other methods, I assume that it would be harder for the "intruder" to get the information you're trying to protect...