Discuss Scratch

Starastar
New to Scratch
44 posts

IP Blacklisting Help

Hello, I am developing a web app. I have simple code to check if an IP is spamming:
if completes > 100:
   blacklist.append(ip)

I add them to the blacklist array but how do I actually black list them from visiting my web app?
MagicCrayon9342
Scratcher
1000+ posts

IP Blacklisting Help

What libraries are in use
What is this being ran on
What is this being ran with

Starastar
New to Scratch
44 posts

IP Blacklisting Help

MagicCrayon9342 wrote:

What libraries are in use
What is this being ran on
What is this being ran with
Flask (for web development)
mysql-connector-python, Pandas (for SQL)
Platform (to get stuff like the IP)
OS, Random (for specific one time use or rare uses)

Localhost!

Python?
applejuiceproduc
Scratcher
1000+ posts

IP Blacklisting Help

Starastar wrote:

MagicCrayon9342 wrote:

What libraries are in use
What is this being ran on
What is this being ran with
Flask (for web development)
mysql-connector-python, Pandas (for SQL)
Platform (to get stuff like the IP)
OS, Random (for specific one time use or rare uses)

Localhost!

Python?
Show the whole code.

Generation 3: the first time you see this copy and paste it on top of your sig in the scratch forums and increase generation by 1. Social experiment.

Linux is cool

AT’s is becoming a dumpster fire

I need internet or north korea gonna blow up the world!!1!!1!1!!

Starastar
New to Scratch
44 posts

IP Blacklisting Help

applejuiceproduc wrote:

Starastar wrote:

MagicCrayon9342 wrote:

What libraries are in use
What is this being ran on
What is this being ran with
Flask (for web development)
mysql-connector-python, Pandas (for SQL)
Platform (to get stuff like the IP)
OS, Random (for specific one time use or rare uses)

Localhost!

Python?
Show the whole code.
why
ajskateboarder
Scratcher
1000+ posts

IP Blacklisting Help

You can use the following:
# add this wherever your imports go
from flask import request, abort
# replace "app" with name of your Flask instance if you don't use "app"
@app.url_value_preprocessor
def check_ban(_, _):
    if request.remote_addr in blacklist:
        abort(403)
url_value_preprocessor is essentially a built-in middleware for checking a request before proceeding. This should send a 403 if a user is in the blacklist

I always seemed to get mad at people in 2022 posts and overuse things like :facepalm: If you are looking at one of those posts, just note I don't write like this anymore
software developer
artist
swimming and biking enjoyer

Starastar
New to Scratch
44 posts

IP Blacklisting Help

ajskateboarder wrote:

You can use the following:
# add this wherever your imports go
from flask import request, abort
# replace "app" with name of your Flask instance if you don't use "app"
@app.url_value_preprocessor
def check_ban(_, _):
    if request.remote_addr in blacklist:
        abort(403)
url_value_preprocessor is essentially a built-in middleware for checking a request before proceeding. This should send a 403 if a user is in the blacklist
Thanks (wait, I should remove my set_page function when it really doesn't do much)
bigspeedfpv
Scratcher
500+ posts

IP Blacklisting Help

oh whats good caroix

cat throwing brick at camera transparent dot gif
https://bigspeed.me
applejuiceproduc
Scratcher
1000+ posts

IP Blacklisting Help

Starastar wrote:

applejuiceproduc wrote:

Starastar wrote:

MagicCrayon9342 wrote:

What libraries are in use
What is this being ran on
What is this being ran with
Flask (for web development)
mysql-connector-python, Pandas (for SQL)
Platform (to get stuff like the IP)
OS, Random (for specific one time use or rare uses)

Localhost!

Python?
Show the whole code.
why
So we can see what's wrong with your code… if there was any code.

Generation 3: the first time you see this copy and paste it on top of your sig in the scratch forums and increase generation by 1. Social experiment.

Linux is cool

AT’s is becoming a dumpster fire

I need internet or north korea gonna blow up the world!!1!!1!1!!

Powered by DjangoBB

Standard | Mobile