Friday, April 20, 2018

Apache - Block IP or an IP Range to prevent opening your site


If you want to block IPs from accessing your site, you can simply achieve it using an htaccess file. Add following line in .htaccess and IP owner will not be able to open your site anymore.


Suppose you want that your site should not be opened from IP 46.161.9.67, you need to add a line your .htaccess file.
Deny from 46.161.9.67
If there are multiple IPs and you want to block them all. Add following line in .htaccess.
Deny from 46.161.9.67 46.161.10.187 46.161.58.89
Block a whole IP Range
Here is the tricky part, If you want to block a whole IP Range like 69.0.0.0 to 69.0.0.255. Use following code in your .htaccess 

Deny from 69.208.0.0/24
If it is from 69.0.0.0 to 69.0.255.255
Deny from 69.208.0.0/16
And If it is from 69.0.0.0 to 69.255.255.255
Deny from 69.208.0.0/8

Refer Link for more wide Range :
https://www.mediawiki.org/wiki/Help:Range_blocks

Sort all files of present working directory and sub directories by modified date and time

If you want to sort all files of a folder and its subfolders by modified date and time, Here is the command.
find . -type f -printf "%T@ %Tc %p\n" | sort -n
Latest modified file will be last in the sequence.

If you want to reverse the sequence i.e. latest modified should be on top.
find . -type f -printf "%T@ %Tc %p\n" | sort -nr

Dot (.) indicates the present working directory. You can use absolute path also.

Laravel Error - No supported encrypter found. The cipher and / or key length are invalid.

While running  composer install or php artisan optimize, If you get this error, here is the solution.

Solution :

Change values in config/app.php

'cipher' => 'AES-256-CBC',
to
'cipher' => MCRYPT_RIJNDAEL_128,

Now run again composer install or php artisan optimize , you will not get the same error again.