Question about ranges in .htaccess

Started by SMiFFER, March 24, 2020, 02:01:26 PM

Previous topic - Next topic

SMiFFER

I am trying to make things shorter here.

I have running:


# 114.119.128-191.*
RewriteCond %{REMOTE_ADDR} ^114\.119\.128\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.129\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.130\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.131\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.132\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.133\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.134\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.135\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.136\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.137\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.138\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.139\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.140\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.141\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.142\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.143\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.144\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.145\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.146\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.147\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.148\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.149\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.150\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.151\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.152\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.153\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.154\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.155\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.156\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.157\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.158\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.159\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.160\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.161\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.162\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.163\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.164\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.165\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.166\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.167\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.168\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.169\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.170\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.171\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.172\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.173\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.174\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.175\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.176\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.177\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.178\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.170\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.180\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.181\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.182\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.183\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.184\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.185\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.186\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.187\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.188\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.189\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.190\. [OR]
RewriteCond %{REMOTE_ADDR} ^114\.119\.191\. [OR]


How can I put this into one line? Is that possible? Like 128-191 does not seem to work.

Help possible and available?
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Shambles

Something along these lines maybe, to give you an idea of what's possible

Code (Try This) Select

RewriteCond %{REMOTE_ADDR} ^114\.119\.[0-9]{1,3}\.[0-9]{1,3}$


Not exactly what you required but adjust to suit

a10

I use the easy way (all 119.*are CN):

order allow,deny
deny from 114.119.
allow from all

alt., huawei only:

order allow,deny
deny from 114.119.128.0/19
allow from all
2.0.19, php 8.0.23, MariaDB 10.5.15. Mods: Contact Page, Like Posts, Responsive Curve, Search Focus Dropdown, Add Join Date to Post.

Shambles

OP didn't mention he wanted to ban the IP range

SMiFFER

Quote from: Shambles on March 24, 2020, 03:17:46 PM
OP didn't mention he wanted to ban the IP range
I would have loved to add more info, but the config here forbids me to edit older posts.
Before I became a FULL MEMBER here I was able to do just that...

More important:
I am having difficulties decyphering.
What exactly does this do: [0-9]{1,3}
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Illori

Quote from: SMiFFER on March 24, 2020, 04:00:33 PM
I would have loved to add more info, but the config here forbids me to edit older posts.
Before I became a FULL MEMBER here I was able to do just that...

does not matter what post count based group you are in, everyone but moderators have 1 hour to edit their posts after they are made.

SMiFFER

OK. Back to the subject.
What exactly does this do: [0-9]{1,3}
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Kindred

a set of 1 to 3 numbers in the range from 0 to 9
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

SMiFFER

Quote from: Kindred on March 24, 2020, 05:52:20 PM
a set of 1 to 3 numbers in the range from 0 to 9
By random?
I do not see how that example (stems from post #2) should help me with my question.
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Kindred

you have a huge list. the stated regex says

RewriteCond %{REMOTE_ADDR}
start with the first two octets:  ^114\.119\. defined
for the third octet, any number from 0 to 999
for the third octet, any number from 0 to 999
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

SMiFFER

An IP address consisting of numbers as high as possibly 999 is invalid.
So would this be a working solution? Or would this cause a bug?


Secondly, I do not want to block 0-255, re-read in post what I defined what.
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Shambles

What I supplied was an example of how you can manipulate the IP address range using a short form of regex.

What exactly do you wish to do with those IP ranges?  Implement a denial/ban for them? If so then a10's suggestion is what you need. If not, please elaborate so we can help you achieve your goal.

a10

My idea was to simply make the 114.119. plague vanish immediately, out of mind, out of sight, out of site.
What I did long ago, rather spending time on more important things in life\forum.
2.0.19, php 8.0.23, MariaDB 10.5.15. Mods: Contact Page, Like Posts, Responsive Curve, Search Focus Dropdown, Add Join Date to Post.

Dave J

As spooky as it may seem only this week I banned that IP (Huawei) and used wild cards to prevent the bot from accessing

IP: 114.119.*.*

If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

SMiFFER

Quote from: Shambles on March 25, 2020, 10:17:58 AM
What exactly do you wish to do with those IP ranges?  Implement a denial/ban for them?

No. I wanted to merge them to make that list shorter.
Like Kindred said, that is a huge list.
The second step comes when I got that done:
I want to redirect all the blocked IPs to an html-page.

Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Dave J

Quote from: SMiFFER on April 04, 2020, 07:00:35 AM
I want to redirect all the blocked IPs to an html-page.

I use this https://custom.simplemachines.org/mods/index.php?mod=2385

Works OK on 2.0.17
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

Kindred

we even give them that bandwidth?   Just deny them from the server period...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

SMiFFER

#17
@davejo

Thanks for your input, but your solution with that mod does not redirect IP ranges, it only redirects banned users,
i.e. users who had been registered users previously. Still not quite what I want.

As I said: I want to redirect all the blocked IPs (IPs! Not banned members!) to an html-page,
i.e. a number of  IP ranges (read post #1).
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Kindred

Quote from: Kindred on April 04, 2020, 11:30:51 AM
we even give them that bandwidth?   Just deny them from the server period...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Dave J

Quote from: SMiFFER on April 04, 2020, 04:51:26 PM
@davejo

Thanks for your input, but your solution with that mod does not redirect IP ranges, it only redirects banned users,
i.e. users who had been registered users previously. Still not quite what I want.

As I said: I want to redirect all the blocked IPs (IPs! Not banned members!) to an html-page,
i.e. a number of  IP ranges (read post #1).

Hi SMiFFER,

I haven't banned any 'users' as such. What I have done is banned IP addresses, so as I previously said I have banned 114.119.*.* which is all Huawei search engines. As long as you know the range of the IP to ban then just input that into the 'Banned Users'. Then I installed the mod and sent all banned users to 'www.google.co.uk' I now don't get any errors in the log where the banned user is trying to do something on the site.

I have attached screenshots of my bans etc. If this still isn't what you're looking for then I'll shut up  ;)
If you want quizzes to add to the new SMF2.1 quiz mod go here . There are also walkthroughs in the forum to explain how to install them and other tips.

Advertisement: