Follow us to get updates regarding Latest posts Follow Now!

How Block a Specific User's IP Address and Redirect them to Another Website?

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

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

how-block-a-specific-users-ip-address-and-redirect-them-to-another-website

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

how-block-a-specific-users-ip-address-and-redirect-them-to-another-website

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

how-block-a-specific-users-ip-address-and-redirect-them-to-another-website

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.

how-block-a-specific-users-ip-address-and-redirect-them-to-another-website

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

how-block-a-specific-users-ip-address-and-redirect-them-to-another-website

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>
Step 10: Paste the Script in your Theme's <head> Section and Click on Save
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.

About the Author

Student | Developer | Blogger

1 comment

  1. Google doesn't recommend to use document.write() as it makes website slower⚠️⚠️
Techy DarshaN's Rules : Leave your opinion or any doubt about this article And is you have any queries please feel free to ask. Don't try to spam, our team reviews every comment.
Have a Cookie!
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.