Welcome to WebmasterWorld Guest from 107.20.5.156

Forum Moderators: open

Message Too Old, No Replies

How do I (using javascript) block/redirect an IP address block?

javascript IP based redirection

     

Chris_C

3:10 pm on Jun 14, 2003 (gmt 0)

10+ Year Member



Hello,

I have an open access members based site that is being frequented by a couple of users that abuse the site, and would like to block their access using javasript. I have found a method to accomplish this, but it only allows for an exact IP match, and they are on dynamic ISP's, so I would like to modify my script to block an IP range.

Below is the script I have. How can I modify it to suit my goal?

Thanks!

Chris C.
******************************
<script language="javascript">
var ip = <!--#echo var="REMOTE_ADDR"-->
if (ip <= '24.55.255.255') {
alert("STOP! You are not authorized to access this page!");
alert("Do not attempt to return, or your computer will begin a self-destruct sequence!");
if (confirm("Please leave now Or you will be forceably removed!"))
{location.href="http://www.google.com" } else { ("OK your choice, doesn't matter to me! SeeYa!"); {location.href="http://www.getalife.com" }} }
</script>

*******************************

tedster

5:08 pm on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld, Chris_C

You can always look at the substrings of any string with javascript, and test them instead of the entire string.

But it's so simple for a user to turn off javascript that this approach is not likely to block your abusers. And if you have any well-behaved users on the same IP range, you'll just alienate them and still have your problem. You really need a server-side solution.

A site search here (top of page) on "block IP address" will return lots of info - mostly in the server-side forums on WebmasterWorld.

Key_Master

5:15 pm on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!--#if expr="${REMOTE_ADDR} = /^24.55./" -->
<script language="javascript">
alert("STOP! You are not authorized to access this page!");
alert("Do not attempt to return, or your computer will begin a self-destruct sequence!");
if (confirm("Please leave now Or you will be forceably removed!"))
{location.href="http://www.google.com" } else { ("OK your choice, doesn't matter to me! SeeYa!"); {location.href="http://www.getalife.com" }}
</script>
<!--#endif -->

[edited by: Key_Master at 5:44 pm (utc) on June 14, 2003]

Chris_C

5:38 pm on Jun 14, 2003 (gmt 0)

10+ Year Member



Well,

Thanks to Key_master for providing an answer to my question, and thanks to tedster for the advice.

I have looked at .htacess usage, but my host does not allow that function. (again, a free hosted site) The biggest challenge I have is that both of the offenders have dynamic IP's, so I am at a loss to create a method to block their individual access, without potentially affecting others within their IP block range.

Chris C.

Key_Master

5:48 pm on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Take note, I made a minor edit to my post above. If you would like you can ban more than 1 IP (or IP range) by separating each entry with the "" character.

E.g.: <!--#if expr="${REMOTE_ADDR} = /^24.55.67.35.8.44/" -->

Remember to change the "" character with a solid vertical pipe.

Chris_C

6:14 pm on Jun 14, 2003 (gmt 0)

10+ Year Member



Keymaster,

Thanks for your info. Although one small problem...lol

I tried the method you prescribed, and it blocked users outside of the IP range also.

I too was blocked and redirected..?

I had to pull it off the page.

I'm a little puzzled on that..

Chris C.

Chris_C

6:20 pm on Jun 14, 2003 (gmt 0)

10+ Year Member



Ok...lol

I just realized the edit you made on your first post..(excluding the "!" from the formula. After I modified it accordingly, it worked.

Thanks again!

Chris C.

Key_Master

6:24 pm on Jun 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're welcome!