homepage Welcome to WebmasterWorld Guest from 54.226.230.76
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

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




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

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




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

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




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

<!--#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




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

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




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

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




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

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




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

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




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

You're welcome!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved