You can use .htaccess file in order to prevent an access to your webpage from specific IP. A .htaccess is a kind of settings file that can be used for things like establishing password-protected directories and to reduce accessibility based on IP. What other things you can do with .htaccess file, read my posts here.
To ban an IP from obtaining your web page, make a .htaccess file within your root folder (usually public_html or www) and add the following settings in the file:
order allow,deny deny from 220.127.116.11 allow from all
It’s easy to know what exactly is going on here. “order allow,deny” is particularly in this order so that the allow rules are checked first, and if someone receive a deny rule, their server request is rejected (i.e. they are blacklisted).
Within the example above, we’re blacklisting 127.0.0.1. In actual use, you will need to modify this to the IP address which you wish to blacklist.You can, of course, blacklist several IP details by adding several deny guidelines on a individual line. For example:
order allow,deny deny from 18.104.22.168 deny from 22.214.171.1242 deny from 126.96.36.199 deny from 188.8.131.52 allow from all
If you want to prevent an whole IP range, you can exclude a particular range in the .htaccess rule:
order allow,deny deny from 42.53.1 allow from all
This will blacklist IP details in the range of 184.108.40.206 to 220.127.116.11.255
If you are not easy to use .htaccess file you may use IP deny manager available into your cPanel to block access to your website.
We have blocked a single IP, multiple IPs and a whole range so far. Whats about blocked a whole country? There are many different IPs blocks that are assigned to a country and it is difficult for any one to short that out by himself. The good thing here is there are several sites that can help us in obtaining a .htaccess optimized IP blocks of any country. ip2location is such a website, you can simply visit it, select the country and then copy paste the whole long output in your .htaccess file.