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.
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

    else {
        # Provide another response.


You can test it by running it with a Chinese internet address:
It will print out
Content-Type: text/plain
Status: 403

At the Github repository there is a version in C as well. This Perl module is based on GeoLite Free Downloadable Databases.

Web links

Copyright © Ben Bullock 2009-2024. All rights reserved. For comments, questions, and corrections, please email Ben Bullock ( or use the discussion group at Google Groups. / Privacy / Disclaimer