How to block all internet traffic from China
The Perl module IP::China provides a way to block all web accesses from China using a Perl script. Here is an example CGI script which demonstrates sending a "forbidden" response if the remote user address is from China.#!/usr/bin/perl use warnings; use strict; use IP::China 'chinese_ip'; my $remote_addr = $ENV{REMOTE_ADDR}; if ($remote_addr) { if (chinese_ip ($remote_addr)) { print <<EOF; Content-Type: text/plain Status: 403 Sorry! EOF exit; } else { # Provide another response. } }You can test it by running it with a Chinese internet address:
REMOTE_ADDR=182.118.20.173 perl block-china.plIt will print out
Content-Type: text/plain Status: 403 Sorry!At the Github repository there is a version in C as well. This Perl module is based on GeoLite Free Downloadable Databases.
Web links
-
Stop Traffic From China IP Address Blocks To Protect Your Web Server From Chinese Hackers
This provides an alternative method, based on the use of server configuration files for the Apache web server.
-
"Relatively easy way to block all traffic from a specific country?" at Serverfault.com
Contains some advice.
-
On blocking Chinese IP addresses
An article from 2005 describing some of the problems.
Copyright © Ben Bullock 2009-2024. All
rights reserved.
For comments, questions, and corrections, please email
Ben Bullock
(benkasminbullock@gmail.com).
/
Privacy /
Disclaimer