Hello Everyone! I am Techy DarshaN, Today on this occasion our Tutorial is How Block a specific User's IP Address and Redirect them to Another Website? If you have annoying visitors to your site, or spammers, you may find it useful to block these users from accessing your website content. You can block bad visitors by IP address or blocks of IP addresses.
What is an IP address?
An IP address is a unique address that identifies or recognizes a device on the internet or a local network. IP stands for "Internet Protocol," which is the set of rules governing the format of data sent through the internet or local network. In addition, IP addresses are the recognizers that allows information to be sent between the devices on a Network: They may contain location information and make devices accessible for communication.
The internet needs a way to differentiate between different computers, routers, and websites so the IP addresses provide a way of doing so and form an essential part of how the internet works.
What is an IP?
An IP address is a string of numbers separated by time periods. IP addresses are represented as a set of four numbers — For example a address might be 192.158.1.38. Each number in the IP can range from 0 to 255. So, the full IP addressing range goes from 0.0.0.0 to 255.255.255.255. Don't think that IP addresses are not just random numbers.
IP Addresses are mathematically produced and allocated by the 'Internet Assigned Numbers Authority' (IANA), a division of the Internet Corporation for Assigned Names and Numbers (ICANN). ICANN is a Non-profitable organization that was established in the United States at 1998 to help and maintain the security of the internet and allow it to be usable by all the daily Internet users allover the world.
Each time whenever anyone registers a domain on the internet, they go through a domain name registrar, who pays a small fee to ICANN to register the domain.
How Block a Specific User's IP Address and Redirect them to Another Website?
Do you have annoying visitors to your site, bots or spammers, you may find this post useful to block these users from accessing your website content. You can block bad visitors by their IP address or blocks of IP addresses. So, Just follow all steps correctly.
Step 1: First of all to block an IP address we need some scripts so to generate them we are using a free Platform Free Hosted Scripts. Go and open this site.
Step 2: A new page will appear if you click on the above link
Step 3: Now 1.Enter the IP Address you want to block ( If you want block multiple IP Addresses don't forget to separate the IP's with commas ( , ) and 2. Enter the URL to which you want to redirect the blocked IP as shown in below image
Step 4: Now click on Generate HTML code
Step 5: You'll be redirected to new page with some Codes select all and copy all those codes
Step 6: Go to your Theme's <head> Section and paste the copied codes and try Save theme, You'll get an error as shown in below image.
Step 7: To solve this error you need to '-->' (inverted comas not included) into document.write code.
Example: document.write('<!--'); to document.write('<!---->'); as shown in below image
It is recommended to add <!----> into the document.write code orelse you may face error
Step 8: After adding that now click on Save Theme.
( OR )
Step 9: Instead of visiting that site and creating Script, Simply copy the below script and add the IP Addresses you want to block with Inverted comas (" ") and comas ( , )
It is recommended to add Ip address with Inverted comas ( " " ) and Comas ( ' )
<script type="text/javascript" src="http://l2.io/ip.js?var=userip"></script>
<script language="Javascript">
function preloadFunc()
{
var ip = userip;
var bannedips=[
"192.158.1.38",
]
var handleips=bannedips.join("|")
handleips=new RegExp(handleips, "i")
if (ip.search(handleips)!=-1){
window.location.replace("http://google.com");
document.write('<!--');
}
}
window.onpaint = preloadFunc();
</script>
Now you have successfully blocked the IP Address and redirected into another site
Conclusion
In this post I have made a step by step tutorial on How Block a Specific User's IP Address and Redirect them to Another Website. I hope you have liked the post and please do with your friends and follow up our blog for awesome content.
If you face any problems in Installing this codes or have any questions pleas feel free to ask in Comments section or join our Telegram Group for discussion.